[R-pkg-devel] Help with detritus on temporary directory note

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Thu May 30 13:43:56 CEST 2024


В Thu, 30 May 2024 11:12:05 +0200
Héctor Meleiro Suárez <hmeleiros using gmail.com> пишет:

> So why is this a problem? Is it that there are too many files aftes
> examples and tests are run? or would this NOTE be an issue to CRAN
> even if only one file was detected at the end?

This problem has two sides.

The side that R CMD check is giving you NOTEs about is that _examples
and tests_ are requried to keep the global state of the system intact.
This includes all files on the computer: writing anywhere except the
tempdir() is prohibited, and even that must be done with care not to
overwrite anything and cleaned up afterwards.

(See https://cran.r-project.org/web/packages/policies.html and search
for "temporary directory".)

The side that's more subjective is that outside tests and examples,
code shouldn't be touching the filesystem without the user's
permission. Many functions (e.g. write.table()) have a legitimate need
to alter the filesystem. If the user would legitimately benefit from not
having to download the files again (including between R sessions), feel
free to follow the advice of Thierry Onkelinx and use
tools::R_user_dir(...), except in tests and examples.

Testing functions that access external resources over the Internet is
fraught with additional peril. Your examples and tests must not fail if
a download attempt fails, but your users will probably prefer your
functions to stop() with an exception on download failure. One way to
solve this problem is to make sure that the functions that fetch
anything from the Internet raise errors with a specific class set and
then to wrap all examples and tests in tryCatch(...,
yourpackage_Internet_error = function(e) message('Caught an error while
accessing an Internet resource: ', conditionMessage(e))). This way any
other unchecked errors (that your tests attempt to uncover) will still
surface.

-- 
Best regards,
Ivan



More information about the R-package-devel mailing list