Skip to content
Prev 3852 / 12125 Next

[R-pkg-devel] Writing to files without altering working directory in R package

I agree that setwd(), tempdir(), etc. clutter up examples.  At the
same time, I respect the CRAN policy - it's conservative approach has
helped us avoid a wild-west working environment. One approach that
might help bring some standardization, instead of each package
developer rolls their own, and avoid having to have that tempdir code
in there is to have example() handle this.  For example, add a
workdir=tempdir() argument to example() and have example() change to
that directory temporarily, and report on the working directory at the
end.
...
Any output files produced by this example may be found in the
temporary working directory '/tmp/alice/Rtmp4faDCv'.

This could be a message or a warning.  One could also imagine using
workdir=getOption("example.workdir", tempdir()) as the default.  If
properly done, this would allow the user to set
options(example.workdir = quote(getwd())) if they'd like to write to
the current directory.

What it does not solve is when a user cut'n'paste code, but maybe that
could be considered acceptable because in that case the user is not
running/source code, but calling it themself.

My $.02

/Henrik




These messages can be skipped if called with example(..., workdir=getwd()).
On Tue, May 7, 2019 at 10:57 AM Duncan Murdoch <murdoch.duncan at gmail.com> wrote: