1

I am looking for a simple student-proof way to specify a custom TMPDIR in R sessions.

R seems unable to expand ~ or $USER, so if I simply write TMPDIR=~/tmp or TMPDIR=$HOME/tmp in .Renviron it does not find the folder, and uses /tmp instead, which is mounted noexec, causing compilation errors for some packages. I have to use the full path to the folder instead, which is different for each student.

The workaround I know of is to set TMPDIR in Bash and export it before calling R, I would like to know if there is a simpler way that does not depend on the actual home directory path. Ideally, I would like to give all students the same .Renviron file, and not have them use the shell at all.

ggll
  • 963
  • 10
  • 13
  • I'm not sure why that isn't working, but putting `local({ Sys.setenv("TMPDIR" = sprintf("%s/tmp", path.expand("~"))) })` in `$R_HOME/etc/Rprofile.site` sets the `TMPDIR` variable correctly (re: `Sys.getenv("TMPDIR")` behaves as expected) on my machine. I didn't test this out by compiling a package, however. – nrussell May 20 '16 at 16:10
  • Thanks for the idea nrussell - but it does not work, I guess setting `TMPDIR` in `.Rprofile` is already too late. Even without installing anything you can test if it worked by calling `tempdir()`. – ggll May 23 '16 at 10:52

1 Answers1

2

I know it has been a while since you posted this question, but I have been using it like this:

TMPDIR = "${HOME}/tmp"
e3vela
  • 56
  • 2
  • 6
  • Hi, I did what you suggested, but the 'TMPDIR' variable still comes out empty for me even after including it in '.Renviron' file. My '.Renviron' file is also in the same folder as the 'tmp'. – Sanjiv Pradhanang Mar 30 '23 at 11:53
  • 1
    @SanjivPradhanang there are different locations were you can have your `.Renviron` file, for example if you want to have the same variables in all your projects but on a user level, the file should be in your home directory, but for project-only variables they should be on the same directory as your project – e3vela Mar 31 '23 at 08:26