Skip to content
Prev 3839 / 12125 Next

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

On 03/05/2019 6:33 p.m., Jarrett Phillips wrote:
Use the tempfile() function to generate a filename in the temporary 
directory.  You might want to use the "pattern" or "fileext" arguments, 
but don't change the "tmpdir" argument.

Then write to that file.

For example,

filename <- tempfile(fileext = ".csv")
write.csv(df, filename)

It's a good idea to clean up afterwards using

unlink(filename)