Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: cannot mkdir R_TempDir

Tags:

r

When attempting to run R, I get this error:

Fatal error: cannot mkdir R_TempDir

I found two possible fixes for this problem by googling around. The first was to ensure my tmp directory didn't contain a load of subdirectories - it doesn't and it's virtually empty. The second fix was to ensure that TMP, TMPDIR, and R_USER in my environment weren't set to non-existent paths - I didn't even have these set. Therefore, I created a tmp directory in my home directory and added it's path to TMP in my environment. I was able to run R once and then I got the fatal error again. Nothing was in the TMP directory that I set in my environment. Does anyone know what else I can try? Thanks.

like image 708
Dan Avatar asked Jun 10 '11 14:06

Dan


4 Answers

Dirk is right, but misses a point: If /tmp is full, you can't create subdirectories there. Try

df /tmp

I just hit this on a shared server, where /tmp is mounted on it's own partition, and is shared by many users. In this particular case, you can't really see who's fault it is, because permissions restrict you seeing who is filling up the tmp partition. Basically have to ask the sys admins to figure it out.

like image 62
naught101 Avatar answered Nov 07 '22 14:11

naught101


Your default temporary directory appears to have the wrong permissions. Here I have

$ ls -ld /tmp
drwxrwxrwt 22 root root 4096 2011-06-10 09:17 /tmp

The key part is 'everybody' can read or write. You need that too. It certainly can contain subdirectories.

Are you running something like AppArmor or SE Linux?

Edit 2011-07-21: As someone just deemed it necessary to downvote this answer -- help(tempfile) is very clear on what values tmpdir (the default directory for temporary files or directories) tries:

By default, 'tmpdir' will be the directory given by 'tempdir()'. This will be a subdirectory of the temporary directory found by the following rule. The environment variables 'TMPDIR', 'TMP' and 'TEMP' are checked in turn and the first found which points to a writable directory is used: if none succeeds '/tmp' is used.

So my money is on checking those three environment variables. But AppArmor and SELinux have shown to be an issue too on some distributions.

like image 45
Dirk Eddelbuettel Avatar answered Nov 07 '22 12:11

Dirk Eddelbuettel


Go to your user directory and create a file called .Renviron and add the following line, save it and reopen RStudio or Rgui or Rterm

TMP = '<path to folder where Everyone has full control>'

This worked with me on Windows 7

like image 39
Youssef Youssef Avatar answered Nov 07 '22 12:11

Youssef Youssef


If you are running one of the rocker docker images (e.g., rocker/verse), you need to map a local directory to the /tmp directory in the container. For example,

docker run --rm -v ${PWD}/tmp:/tmp -p 8787:8787 -e PASSWORD=password rocker/verse:4.0.4

where ${PWD} for me is ~/devProjs/r, and I created a /tmp directory inside it, so that the container's /tmp is mapped to my ~/devProjs/r/tmp directory.

like image 1
hkong Avatar answered Nov 07 '22 13:11

hkong