R temp working directory different from project directory

Is it possible to have RStudio reference a different directory than that referenced by a Project? I want project specific files to be referenced in their directory, but I also want RStudio temporary working files, those that have the weird numbers associated with them, to be in another directory.

What potential exists for project files to be be separated from temporary working files?

the tempdir() function might be a good option for you

Is there a way to have a "permanent" tempdir() that loads everytime RStudio does?

I'm not sure I understand your requirement. temporary/permanent to me are antonyms :slight_smile:

Yes, I suppose there is an issue with the antonyms... My bad.

Let me see if I can clarify...

When RStudio loads, temporary files are created to help it perform its functions/operations. If you are working in a Project, then the temporary files are created in the directory with the Project files. If you are not working in a Project, then the temporary files are created in a default directory you can specifiy in the settings. Those temporary files are then deleted when you close RStudio, no matter whether there is a Project loaded or not. The project files, however, stay in the Project directory.

Is there a way to set where those temporary files are always referenced, which may differ from where Projects reference Project related files.

I've never seen temporary files show up in my project directories, but maybe this is OS-related behavior. Do you have an example of a command that would create temporary files in your projects?

I attach a screen capture of the temporary files loading with R. I hope you can see the numeric files, along with other panes, etc. (Please ignore the pdfs and toher files.)

Those files are certainly being modified as you use R, but they're not visible in the project directory (although your Dropbox app is detecting changes in them). I guess it's not clear what you're trying to achieve or why -- do these files somehow get in the way? If so, could you say how?

Yes, those are hidden R files that open/get modified for projects. You are correct, the problem is not with RStudio directly, but the interaction with files that are in the cloud cause constant 'syncing' that slows down my processing. Sure, I could turn-off sync, then turn back on, but if there was a way to have those hidden files off to the side in a non-dropbox folder/directory, it would be great.

Possible?

Have you tried with the preview version of RStudio(v1.3.820)? It is supposed to be more Dropbox friendly

Auto Save

  • Changes automatically (and optionally) saved to disk after a few seconds or when editor loses focus (#5263)
  • Option to disable real-time backup of unsaved changes to avoid conflicts with Google Drive, Dropbox, etc. (#3837)
  • Option to adjust idle interval for backup or saving changes

If that doesn't help then I think you could make a "feature request" on the GitHub repo.

1 Like

Not sure an Ubuntu version is available yet, but nonetheless, disabling real-time backup is not what I am looking for - although it may help. I am not sure how to formualte this, but what I seek is a setting in RStudio that allows me to designate a temporary, or in the old days a "scratch" folder, that is only 'live' during the session. I realize there will be temporary files that always have to be accessed, which is fine for me, but if there was an option to select where those temporary files are located, that would be very helpful.

What next?

I don't think that functionality is implemented, as I said before, you may try making a feature request on the GitHub repo and see what the developers think about it.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

See the documentation in ?tempdir. In particular:

By default, tmpdir will be the directory given by tempdir() . This will be a subdirectory of the per-session temporary directory found by the following rule when the R session is started. The environment variables TMPDIR, TMP and TEMPare checked in turn and the first found which points to a writable directory is used: if none succeeds ‘/tmp’ is used. The path should not contain spaces. Note that setting any of these environment variables in the R session has no effect on tempdir() : the per-session temporary directory is created before the interpreter is started.

In other words, you likely need to set the TMPDIR environment variable, and need to set it in a project-specific way. You could accomplish this by setting this in a project-local .Renviron file; e.g.

TMPDIR = /path/to/tmpdir

See ?Startup for more details on how .Renviron works and how those files are read during startup.