Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does `build_setup_source` delete `inst/doc`? #58

Closed
mlysy opened this issue Nov 2, 2018 · 17 comments
Closed

Why does `build_setup_source` delete `inst/doc`? #58

mlysy opened this issue Nov 2, 2018 · 17 comments

Comments

@mlysy
Copy link

@mlysy mlysy commented Nov 2, 2018

This behavior affects the package developer's source directory and is unavoidable when build(vignettes = TRUE). I am curious as to whether this step is necessary, or merely to avoid putting unnecessary things in the the resulting tarball.

If it is the latter, would you consider making (or allowing me via PR to make) it optional? The (longish) reason for the request follows below.


If inst/doc is forcibly deleted, this essentially precludes the possibility of including other (non-vignette) documentation in inst/doc via any other mechanism than vignettes/.install_extras. This particularly concerns a package I am developing (with @nevrome) which manages the Doxygen documentation for a developers C++ code.

Doxygen creates HTML documentation with subdirectories to which the entry point is a main file Doxygen/index.html. Unfortunately .install_extras does not preserve folder structure, so we would be forced to include the Doxygen doc via a non-standard location, e.g., inst/Doxygen.

This is perhaps merely an aesthetic concern, except we would also like to provide an entry point to the Doxygen documentation via an R vignette. This can easily be achieved from the Rmd file with the HTML "redirect"

<meta http-equiv="refresh" content="0; URL=path/to/Doxygen/index.html">

However, R forbids any redirects to files stored anywhere other than within inst/doc. Given the ubiquitous usage of devtools/pkgbuild by our intended developer base, I was curious as to whether there is a way around the deletion of inst/doc.

@jimhester
Copy link
Member

@jimhester jimhester commented Nov 2, 2018

Unfortunately .install_extras does not preserve folder structure

This is not true, you can copy folders with the full structure. But you have to be careful how you construct the regular expression in .install_extras.

E.g. if I want to copy the test folder and containing files in vignettes/test you need to only have

^vignettes/test$

In your .install_extras file. Using $ to restrict to only matching the folder is important.

@mlysy
Copy link
Author

@mlysy mlysy commented Nov 2, 2018

I stand corrected, thank you for pointing this out :)

One thing though is that Doxygen documentation is not negligible in size -- about 100KB (compressed) of overhead for any project (but scales relatively well with project size). So, if possible I'd like for the Doxygen doc not to be duplicated for the purpose of uploading to CRAN.

Would love to hear your thoughts on this if you get a chance.

@mlysy
Copy link
Author

@mlysy mlysy commented Nov 2, 2018

Actually this can be achieved by adding a line to .Rbuildignore.

Anyways, thank you very much for your help.

@mlysy mlysy closed this Nov 2, 2018
@mlysy
Copy link
Author

@mlysy mlysy commented Nov 4, 2018

Out of curiosity, would it be possible to answer the original question? I really would like to benefit from your insights as to why the standard source location for package documentation ought to be changed from inst/doc to vignettes.

@mlysy mlysy reopened this Nov 4, 2018
@jimhester
Copy link
Member

@jimhester jimhester commented Nov 5, 2018

It is extremely common for authors to mistakenly have stale vignette outputs in inst/doc, and very rare to have non-vignette generated docs.

@jimhester jimhester closed this Nov 5, 2018
@mlysy
Copy link
Author

@mlysy mlysy commented Nov 6, 2018

Thank you for the explanation -- this makes perfect sense.

Might you consider a minimal PR to make the deletion by default but optional? I was thinking along the lines of a clean_inst_doc argument to pkgbuild::build, with default value TRUE producing exactly the same behavior (i.e., with interactive prompt) as the current setup...

@gaborcsardi
Copy link
Contributor

@gaborcsardi gaborcsardi commented Nov 6, 2018

@mlysy that will not take you very far, because pkgbuild is often called downstream, e.g. by rcmdcheck or remotes::install_github() where you cannot supply any arguments.

@mlysy
Copy link
Author

@mlysy mlysy commented Nov 6, 2018

I realized this (too late), and would have liked to amend my suggestion to the prompt asking whether or not to delete inst/doc, but not to exit prematurely if the answer is "no" (and not to delete outside of interactive() mode, in which case I should think there's less risk of passing forward stale contents of inst/doc to the build).

Forgive me for being persistent, but I do hope there is some value in encouraging R package developers to better document their C++ source code, for which Doyxgen (in my mind) is the ideal software. Due to the ubiquitous usage of devtools/pkgbuild among these developers, I think it is important for rdoxygen to be fully compatible with it.

I should also point out that the approach above of

  1. putting the Doxy doc in vignettes/doxygen,
  2. sending it to inst/doc on build via .install_extras,
  3. and .Rbuildignoreing the vignettes copy so as not to waste space on CRAN

breaks if devtools::install() or pkgbuild::build() is (re-)run on the extracted tarball, as vignettes/doxygen in the extracted source no longer exists...

Therefore, might a PR to the effect of modifying the prompt from "accept that inst/doc will now be delete" to "decide whether inst/doc will now be deleted" be something that you would consider?

@gaborcsardi
Copy link
Contributor

@gaborcsardi gaborcsardi commented Nov 6, 2018

This setting belongs to the package, so ideally, you would be able to request this behavior in DESCRIPTION.

But can't you just put the docs in inst/docs or inst/cdocs or something like that? Doesn't that solve this issue?

@mlysy
Copy link
Author

@mlysy mlysy commented Nov 6, 2018

The problem is that if we wish to access the Doxygen doc as a vignette, our HTML redirect (see above) only works for installed packages if the Doxy doc is in a subfolder of doc (more info here). The exact error message (displayed in the web browser) is:

Only help files, NEWS, DESCRIPTION and files under doc/ and demo/ in a package can be viewed

I suppose we could backdoor the Doxygen doc through inst/demo (haven't tested this yet), but I'm still clinging to the hope that a minor modification to pkgbuild would be preferable...

@gaborcsardi
Copy link
Contributor

@gaborcsardi gaborcsardi commented Nov 6, 2018

I see. Then maybe a custom field in DESCRIPTION that tells pkgbuild not to delete (some of?) these files, is the best solution.

@mlysy
Copy link
Author

@mlysy mlysy commented Nov 6, 2018

If this is something that you (the developers of pkgbuild) would be open to, then it would be my utmost pleasure to submit a PR. Just let me know :)

@gaborcsardi
Copy link
Contributor

@gaborcsardi gaborcsardi commented Nov 6, 2018

I think for sg like pkgbuild, that is often called downstream, it makes sense to have config in DESCRIPTION.

@jimhester what do you think?

@ldecicco-USGS
Copy link

@ldecicco-USGS ldecicco-USGS commented Jan 31, 2019

I still don't understand this behavior (after reading through this discussion).... probably because I'm just too stuck in my ways. My current (probably soon-to-be-former) process for checking my package before sending it to CRAN was:

  1. Click the "Install and Restart" button in RStudio
  2. Run devtools::build_vignettes() to absolutely make sure I had the current versions of the vignettes in the inst/doc folder
  3. Run tools::compactPDF on any old-school .Rnw vignette
  4. Click the "Check" button in RStudio (4.5 cross fingers...)
  5. Click the "Build Source Package" and send that file to CRAN assuming no notes/warnings/errors

Now I'm just nervous about everything. I can't run check() without deleting the inst/doc folder. build_vignettes doesn't put the vignettes there anyway. So, via devtools - I will always get a warning for not compacting the pdf vignettes (right?).I have to live with the Warning, move the doc folder manually into inst/doc, run tools::compactPDF, then build the source.

Am I just living in the past and there's a better way to develop packages now?

"inst/doc" is still the canonical home for vignettes on CRAN, correct? ie...CRAN doesn't rebuild the vignettes, or has that changed? I'm basing my understanding on:
https://stat.ethz.ch/pipermail/r-package-devel/2017q1/001273.html

davidcsterratt added a commit to davidcsterratt/geometry that referenced this issue Feb 11, 2019
davidcsterratt added a commit to davidcsterratt/geometry that referenced this issue Feb 11, 2019
The devel version of R (as of 2019/02/11) wants to delete the inst/doc
directory when building, in preparation for putting vignettes
there. This breaks the Qhull docs, which are in inst/doc. To work
around this, the qhull docs need to be moved to vignettes/qhull, and
included using vignettes/.install_extras. Various links need to be
changed too. See r-lib/pkgbuild#58 for explanation of the behaviour.
@jimhester
Copy link
Member

@jimhester jimhester commented Feb 11, 2019

I would just use use devtools::build(vignettes = TRUE) to build the package with vignettes, then send that to CRAN.

bpbond added a commit to bpbond/cosore that referenced this issue Apr 15, 2019
Nelson-Gon added a commit to Nelson-Gon/manymodelr that referenced this issue Jun 23, 2019
@Nelson-Gon
Copy link

@Nelson-Gon Nelson-Gon commented Jun 29, 2019

I know this is an old thread but inst/doc seems to be required to build vignettes. Having vignettes in vignettes does not build vignettes as required. Is there a workaround?

@Enchufa2
Copy link

@Enchufa2 Enchufa2 commented Nov 29, 2019

I arrived here due to a similar issue. Basically, when I develop a package for a client, I sometimes have several very big vignettes with expensive computations that I want to build once and keep both the static HTML/PDF and the Rmd.

FYI, I found a nice solution. I put those Rmds under vignettes, but without any VignetteIndexEntry stuff in the YAML header. Then, I call rmarkdown::render whenever I want to build them. And, finally, I follow the instructions here to include static vignettes.

TL;DR:

$ ls -1 vignettes/
test.html
test.html.asis
test.Rmd
$ cat test.html.asis
%\VignetteIndexEntry{Test vignette title}
%\VignetteEngine{R.rsp::asis}
%\VignetteEncoding{UTF-8}

And add R.rsp to Suggests and VignetteBuilder in your DESCRIPTION file (you may have several vignette builders listed there, and mix static and dynamic vignettes).

vi-to added a commit to JustinMShea/ExpectedReturns that referenced this issue Jul 4, 2020
Modulo some LaTeX re-running warnings, devtools::build_vignettes() is able to construct vignettes with \VignetteEngine{knitr::rmarkdown}. Yet devtools::check() returns vignettes building errors. This does not appear to me to be a building error in the sense of <R CMD build>, but a <R CMD check> error. A wild guess I can attempt is that the check fails because the former builds from 'vignettes/', whereas the latter rebuilds from another (copied) directory (e.g. 'inst/doc/') and is then unable to find parsers' paths.

Nonetheless, \VignetteEngine{rmarkdown::render} is maybe only a workaround and check results report a WARNING of the form:
"Files named as vignettes but with no recognized vignette engine:
      ‘vignettes/*.Rmd’
   (Is a VignetteBuilder field missing?)
Files named as vignettes but with no recognized vignette engine:
     ‘vignettes/*.Rmd’"
The topics is being discussed right at r-lib/pkgbuild#58.

From Writing R Extensions: "When R CMD build builds the vignettes, it copies these and the vignette sources from directory vignettes to inst/doc. To install any other files from the vignettes directory, include a file vignettes/.install_extras which specifies these as Perl-like regular expressions on one or more lines. (See the description of the .Rinstignore file for full details.)" (https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Writing-package-vignettes). Please note this however doesn't directly apply to our problem, as vignettes root.dir is at package root dir. We may be able to better manage the process via '.install_extras'.

A related problem arising during checks is as follows. knitr, among other things, produces *.pdf and separates *.R "runnable" scripts from vignettes. As mentioned in 57f28ce, the "HML Devil" parser introduced by a98c0f8 is a potential source of problems. The file shares its name with the vignette, but to my knowledge this is also knitr's default behaviour when extracting runnable code, so what is going on would be that in the check process the file gets overwritten and hence never executes the parser. It should be why knitr is then understandably unable to find objects and as a consequence errors out. In order to show the effects of the attempted fix I'm momentarily copying @JustinMShea and @erolbicero's parser to inst/parsers/, where all the other parsers are.

Please note, I am not 100% sure this is the ideal solution, but with the present commit the check is satisfied as opposed to clogged by apparently exotic "building" errors. In particular, it only produces 1 WARNING to my knowledge. Our current Travis config will fail builds WARNINGs, but at the same time '--no-build-vignettes' options are passed, so the vignette building WARNING is hidden to Travis and hence both local and Travis builds&checks should succeed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.