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

Uwe Ligges ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de
Sat May 4 00:37:50 CEST 2019



On 04.05.2019 00:33, Jarrett Phillips wrote:
> Hello,
> 
> My R package has a function with an argument to specify whether numerical
> results should be outputted to a CSV file.
> 
> CRAN policy stipulates verbatim that
> 
> 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). Installing into
> the system’s R installation (e.g., scripts to its bin directory) is not
> allowed.
> 
> I know I should use tempdir() within my package function, but I've not seen
> any examples on how this is best done within existing R packages.
> 
> Within my package documentation examples for my function, I have the lines:
> 
>   \dontshow{.oldwd <- setwd(tempdir())}


1. the user who copies the example to the R console does not change to 
the tempdir() and still overwrites files in her/his filespace.

2. And even if you o not wrap this in \dontshow, a user may oinly copy a 
part and then changes the workdir.

Why not simply use tempdir() in the code that writes the file in the 
example?

Best,
Uwe Ligges

> ... some R code ...
> 
> \dontshow{setwd(.oldwd)}
> 
> but I have been informed that this is not the accepted way.
> 
> Any ideas from the community on how do do this properly?
> 
> 
> Thanks for the help!
> 
> Cheers,
> 
> Jarrett
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list