Why is on.exit not allowed in examples on CRAN?

Viewed 28

I submitted a package to CRAN with the following setup code for a temp file, within an example in the documentation:

#'   conn <- DBI::dbConnect(RSQLite::SQLite(), tmp <- tempfile())
#'   on.exit(DBI::dbDisconnect(conn), add=TRUE)
#'   on.exit(file.remove(tmp), add=TRUE)

I received the form letter back:

Please make sure that you do not change the user's options, par or
working directory. If you really have to do so within functions, please
ensure with an *immediate* call of on.exit() that the settings are reset
when the function is exited. e.g.:
...
old <- options()         # code line i
on.exit(options(old))      # code line i+1
...
options(digits = 3)
...
If you're not familiar with the function, please check ?on.exit. This
function makes it possible to restore options before exiting a function
even if the function breaks. Therefore it needs to be called immediately
after the option change within a function.

Please always make sure to reset to user's options(), working directory
or par() after you changed it in examples and vignettes and demos.
e.g.:
old <- options(digits = 3)
...
options(old)

However, if I set a breakpoint using debug(file.remove) and run it with example(myfun) I can clearly see the temporary file get deleted appropriately.

What is the rationale behind this request?

0 Answers
Related