26

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.

Dan
  • 263
  • 1
  • 3
  • 4

10 Answers10

30

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.

naught101
  • 18,687
  • 19
  • 90
  • 138
23

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • I'm afraid it's not that simple. I've got a machine now exhibiting this same problem and TMP is set to /tmp, and permissions for /tmp are correct. There doesn't appear to be anything in the system logs that indicates a problem either. – Brian G. Peterson Jul 21 '11 at 16:56
  • aren't they supposed to log stuff to tell us what's going on? – Brian G. Peterson Jul 21 '11 at 17:04
  • If the code is written such that it logs, yes. Your fault in assuming all code does. – Dirk Eddelbuettel Jul 21 '11 at 17:06
  • See expanded answer -- at some point a simple `mkdir()` call fails. You need to think through why / where. Start by setting `TMPDIR` to something like `$(HOME)/tmp` (and make sure it exists). – Dirk Eddelbuettel Jul 21 '11 at 17:24
  • 1
    I had this error. Even though the permissions looked fine "ls -ld /tmp" and I had space on my drive (df) my OS said that /tmp was read-only. I rebooted, and the OS (Ubuntu 14.04) said there was a problem on my root partition. I chose to try Fixing it (from Fix, Ignore, Manual). Very quickly after that, my machine rebooted again, and then it came up cleanly and the problem is gone. Daily backups...! – CPBL Sep 19 '14 at 14:15
  • I faced same error wihile `$ sudo chmod 777 /tmp` doen't help. Any solution? – Rγσ ξηg Lιαη Ημ 雷欧 Apr 21 '16 at 08:31
2

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

naught101
  • 18,687
  • 19
  • 90
  • 138
Youssef Youssef
  • 153
  • 2
  • 6
1

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.

hkong
  • 8,222
  • 1
  • 19
  • 15
0

Just had this issue and finally solved it. Simply a windows permission issue. Go to environment variables and find the location of the temp folders. Then right click on the folder > properties > security > advanced > change everyone to full control > tick "replace all child object permission entries with inheritable permission entries from this object" > Ok > ok.

0

This will also happen when your computer is completely, utterly out of space. Currently, my Mac has 0 kb free and it's causing this error. Freeing up some space solved the problem.

n8sty
  • 1,418
  • 1
  • 14
  • 26
0

Check for the user account with which you are launching the RStudio with. Now u check the TMP(System Environment variable) for its location. If the user who is launching RStudio has Write access for those directories you will not face this issue. Being said that you are facing this issue, all you have to do is to change the permissions for that user to have write access on those directories.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
0

Running R on CentOS system and had the same issue. I had to remove all R folders from the tmp directory. Usually all R folders will be in the form of /tmp/Rtmp***** so i tried to delete the folders from /tmp by running the below.

CD into /tmp directory and run rm -rf Rtmp*

R shell Worked for me afterwards

0

I had this issue, solution was slightly different. I run R on a linux server - it turned out for me R had made a whole load of tempdirs when running jobs with cron that had hung and not been cleaned up, clogging up the root /tmp directory with ~300 RtmpXXXXXX folders.

Using terminal access, I navigated to the /tmp folder did a recursive find/rm - deleting all of them using this command:

find . -type d -name 'Rtmp*' -exec rm -r -v {} \;

After this, Rstudio took a while to load up, but was once again happy and my scripts began to run again.

You will need the appropriate admin rights for this solution. And always be careful when running rm -r, especially with a find command, as it's easy to remove things unexpectedly.

cc101
  • 31
  • 3
0

When it comes to deleting tmp files, make sure that the tmp files are in the server or in local.

If its in the remote, 1st check for the df /tmp in the server or in the remote to see who uses more storage.

Then use rm(file_name)` to remove the files which cause the blocking.

If its in the remote, then use rm /tmp/(file_name)..

MOreover, you can also refer to https://support.rstudio.com/hc/en-us/articles/218730228-Resetting-a-user-s-state-on-RStudio-Server