Reputation: 100164
I want to write some temporary data to disk in an R package, and I want to be sure that it can run on every OS without assuming the user has admin rights. Is there an existing R function that can provide a path to a temporary directory on all major OS's? Or a way to reference a user's home directory?
Otherwise, I was thinking of trying this:
Sys.getenv("temp")
I presume that I can't expect people to have write access to their R locations, otherwise I could reference a path within the package directory: .find.package("package.name")
.
Upvotes: 7
Views: 2912
Reputation: 121077
Yes, there is: tempdir
.
This will return a session specific directory within the user's temp directory. (So it gives the same value every time you call it within a specific R session. Shut R and restart, and it will give you a different directory.)
pathological::temp_dir
provides a more user friendly wrapper.
Upvotes: 10
Reputation: 100164
After some further thought, I think that this should work:
path.expand("~")
That will give the home directory, which should have write access.
Upvotes: -1