[R-pkg-devel] R CMD check failure during vignette rebuilding

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Tue Apr 14 14:53:02 CEST 2020

On 14/04/2020 6:23 a.m., Konrad Rudolph wrote:
> I have a package vignette that reproducibly fails the second time
> round in `R CMD check`, in the “checking re-building of vignette
> outputs” step.
> I have uploaded a small reprex to GitHub [1]. But in a nutshell the
> vignette contains a subfolder `foo`, and a file `foo/bar`. And the
> `test.rmd` vignette contains the following R code:
>> newfile = file.path(getwd(), 'foo', 'baz')
>> writeLines('baz', newfile)
> This code causes `R CMD check` to delete the folder `foo` inside
> `00_pkg_src/vignettes` after building the vignette, leading to the
> following error message further down the line:
>>    Error(s) in re-building vignettes:
>>      ...
>>    --- re-building ‘test.rmd’ using rmarkdown
>>    Quitting from lines 8-10 (test.rmd)
>>    Error: processing vignette 'test.rmd' failed with diagnostics:
>>    cannot open the connection
>>    --- failed re-building ‘test.rmd’
> This seems to be due to the cleanup after building vignettes inside
> `tools::buildVignette`, because creating a file inside a folder
> changes the directory subfolder modification time (on POSIX-like
> systems) so the whole folder is deleted in cleanup, rather than just
> the file. Can I prevent this?
> [1] https://github.com/klmr/vignettetest

Normally the checks don't want you to be writing files outside of the 
temp dir, because if a user processed your vignette, it might stomp on 
their files.  So can't you change that code to

   dir.create(tempdir(), 'foo')
   newfile <- file.path(tempdir(), 'foo', 'baz')

Duncan Murdoch

More information about the R-package-devel mailing list