[Rd] RMarkdown Vignettest in R packages with child is failing in package build

Duncan Murdoch murdoch@dunc@n @ending from gm@il@com
Tue Jul 10 19:52:38 CEST 2018

On 10/07/2018 11:44 AM, Witold E Wolski wrote:
> Dear List,
> I am working on moving some Rmarkdown reports into the vignettes
> folder of a package. While I was able to solve to problem of
> parametrized reports in vignettes folder thanks to your invaluable
> help (Thank you), I am now struggling with the following problem.
> One of the reports which I am moving to vignettes includes the following code :
> ```{r}
> child_docs <- "Grp2Analysis_MissingInOneCondtion.Rmd_t"
> if(TRUE){
>    child_docs <- "Grp2Analysis_Empty.Rmd_t"
> }
> ```
> ```{r includeMissingInOne, child = child_docs}
> ```
>     # this is line 351 from the error message
> which depending on a test outcome includes one or the other Rmarkdown
> document into the main document.
> While this report renders executing rmarkdown::render or
> devtools::build_vignettes, it fails when building the package with
> devtools::build or R CMD build
> given the following error:
> Error in eval(x, envir = envir) : object 'child_docs' not found
> Warning in readLines(if (is.character(input2)) { :
>    cannot open file './child_docs': No such file or directory
> Quitting from lines 351-351 (./child_docs)
> Error in readLines(if (is.character(input2)) { :
>    cannot open the connection
> ERROR: installing vignettes failed
> * removing 'C:/Users/wolski/AppData/Local/Temp/RtmpIti891/Rinst2cec49ca2170/SRMService'

Since you didn't give a path to that file, it will use the current 
working directory, which might be a temporary directory used during the 
package installation.  Since you want this to work as a vignette, you 
need to include the child docs in your package.  One way to do that is 
to put them in a new directory called "inst/children", which will be 
installed to "children" when your package is installed.  Then the 
vignette can find the file as

     system.file(file.path("children", child_docs), package = "yourpackage")

You could also put them in the "vignettes" directory, but there are 
special rules for how files there are installed or not, so I'd recommend 
against it.

Duncan Murdoch

More information about the R-devel mailing list