Writing temporary data from R

I want to write temporary data to disk in an R-package, and I want to be sure that it can work on every OS, without assuming that the user has administrator rights. Is there an existing R function that can provide a path to a temporary directory on all major operating systems? Or a way to link to the user's home directory?

Otherwise, I thought about it:

Sys.getenv("temp") 

I assume that I cannot expect people to have write access to their R-locations, otherwise I could reference the path in the package directory: .find.package("package.name") .

+6
r
source share
2 answers

Yes there is: tempdir .

This will return the session-specific directory to the temp user directory. (This way, it gives the same value every time you invoke it for a specific session of R. Close R and restart, and it will give you a different directory.)

pathological::temp_dir provides a more user-friendly shell.

+10
source share

After some further thought, I think this should work:

 path.expand("~") 

This will give a home directory that should have write access.

-one
source share

All Articles