[R-pkg-devel] Creating temporary files in tests/examples/vignettes - adhering to CRAN policies
Daniel Kelley
ke||ey @end|ng |rom d@|@c@
Mon Nov 11 15:26:12 CET 2024
I think the idea is to do as below. You can also make temporary directories in a similar way.
tempFile <- tempfile()
# write to tempFile, and use it anyway you like
unlink(tempFile)
> On Nov 11, 2024, at 9:22 AM, Alexander Pate <alexander.pate using manchester.ac.uk> wrote:
>
> CAUTION: The Sender of this email is not from within Dalhousie.
>
> Hello,
>
> The CRAN policies (https://cran.r-project.org/web/packages/policies.html) for R package development state:
>
> "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)."
>
> If a file is created in the R session's temporary directory, does it then need to be cleaned up? Or does it only apply "during installation in the location pointed to by TMPDIR". I am unsure, given the "and such usage should be cleaned up" is contained within the brackets, whether it applies to creating files in the temporary directory during function examples/vignettes/tests.
>
> For example, the following command will create an SQLite database in the R session's temporary directory:
>
> testdb <- RSQLite::dbConnect(RSQLite::SQLite(), tempfile("temp"))
>
> Suppose a package function (called: myfunc) runs this command. Should the file created in the temporary directory have to be removed after running an example of myfunc, or a test for myfunc, or when myfunc is used in a vignette?
>
> I think part of my confusion comes from not understanding what TMPDIR is during installation. Is this just the temporary directory used when vignettes are built during package installation? In which case they are effectively the same thing?
>
> Many thanks
>
>
> [[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