No, I can't tell you whether the behaviour you saw was intentional or not, I didn't write it. But the CRAN policy (which is the motivation for many of the checks) says "Packages should not write in the user’s home filespace (including clipboards), nor anywhere else on the file system apart from the R session’s temporary directory (or during installation in the location pointed to by TMPDIR: and such usage should be cleaned up)."

Duncan Murdoch

On 14/04/2020 12:22 p.m., Konrad Rudolph wrote:
Hi Duncan,

Thanks for the explanation. Using a temporary directory is what I’m
doing at the moment as a workaround.

What confused me was that `R CMD check` *already* works inside a new
directory (a set of different ones, in fact), and it doesn’t seem to
be documented anywhere that this is the intended behaviour (the
documentation of `buildVignettes` only mentions it removes “newly
created … files”, not existing folders), so I thought creating
temporary files under `vignettes` was fair game. Could you clarify
whether this behaviour (deleting existing folders during cleanup) is
intentional? If so, could it be documented more explicitly?“


On Tue, Apr 14, 2020 at 1:53 PM Duncan Murdoch <murdoch.dun...@gmail.com> wrote:

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



--
Konrad Rudolph // @klmr


______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to