Twitter

Tuesday, November 13, 2007

Temp Directory and Working Director of R

For a while, I have been using the setwd() command at the beginning of a project's code. This allows one to save data, graph, output easily to a project's result folder without typing long path names.

Yesterday, I was using a contributed package in R that requires the access to R's temp directory. The exact location of this folder can be found out using the command tempdir(). It just happened that my current location of this folder was not ideal for the task at hand and I needed to change it. There was no command in R to change it. I figured out a way to do it: add an entry to the environmental variable list of the system as TMPDIR and specify the desired folder name.

1 comment:

Anonymous said...

Usually the environmental variable "TMPDIR" has already been specified (e.g. as "C:\\WINDOWS\\Temp" in Windows) so you don't need to add it again. To get this directory, you may as well use Sys.getenv():

> Sys.getenv("TMPDIR")
TMPDIR
"C:\\WINDOWS\\Temp"