80

So I'm using RStudio and storing my files on Google Drive (the version with folders on your system, acting like Dropbox). I'm using it because it provides a lot more space for free than Dropbox, and I need that space for the projects I'm working on.

When I attempt to write any document at all -- an R script, an RMarkdown file, etc... -- I get the error mentioned in the title. This doesn't happen using Dropbox. I have found answers for this question for Dropbox, but the solution (tell Dropbox not to sync the Rproj file) doesn't seem applicable to Google Drive (if it is, please correct me).

Currently, I'm pausing Google Drive, which is fine, but I often forget to resume it and that causes headaches.

Thanks for your help!

jpm_phd
  • 915
  • 1
  • 6
  • 8
  • 4
    Did you ever find a solution to this problem? I'm having the same issue. – Ryan Haunfelder Aug 18 '16 at 19:50
  • Someone complained about this in 2015 in RStudio's forum. https://support.rstudio.com/hc/en-us/community/posts/204261768-The-process-cannot-access-the-file-because-it-is-being-used-by-another-process?page=1#community_comment_218262748 I cross referenced this question there, too. – Fuhrmanator Aug 19 '16 at 15:47
  • RStudio is creating semi-hidden files inside the directory `.Rproj.user`, and Google Drive tries to sync them. Google Drive has a preference to stop syncing certain directories, so I tried setting that for `.Rproj.user`. As a consequence, Google Drive deletes that directory on your hard drive. However, the next time RStudio creates something new in it, Google Drive goes ahead and tries to sync the new files that aren't on it's don't-sync list. Since the filenames seem to change from one RStudio session to the next, this doesn't work. – Fuhrmanator Aug 19 '16 at 16:25
  • Darby Hadley at RStudio has logged it as a bug: https://support.rstudio.com/hc/en-us/community/posts/211694187-RStudio-Google-Drive-autosave-clash#community_comment_218250368 – Fuhrmanator Aug 19 '16 at 16:37
  • I'm really glad. Still no way around it that I've found. Can't wait for them to fix it. For the longest time, I couldn't find any resources about this. – jpm_phd Aug 19 '16 at 21:35
  • 3
    Isn't that rather a Google drive bug? – jan-glx Oct 04 '16 at 17:15
  • 3
    @YAK - Since we can run many other programs such as Microsoft Word which creates temporary files in the directory without running into issues, I'd think this is probably a problem with the way RStudio handles files. I Agree with Darbey Hadley that RStudio should save AppData for the project to the %APPDATA% folder instead (or at least have an option for that) – Michael Tallino Dec 15 '16 at 21:22
  • @psalmody No, most programs, including MS Word have problems running in Google drive - they are just not as apparent. If you save a large file (with images) in word twice to google drive, the second save will ask you for another location to save your file (if google drive is syncing the file in that moment), similarly Photoshop will often show an error if you try to resave a file to google drive. The temporary file MS Word creates is just a lock file (in contrast to the working copy rstudio stores). ... – jan-glx Dec 16 '16 at 11:05
  • ... No doubt Rstudio could work around this problem (and no doubt that this would make many people (including me) very happy), but problem's root clearly lies with google. – jan-glx Dec 16 '16 at 11:06
  • 2
    See also my answer here: http://stackoverflow.com/a/41039847/1870254 – jan-glx Dec 16 '16 at 11:19
  • 1
    Hi! Any update on the issue? – ikashnitsky Dec 04 '17 at 11:12
  • 1
    Its not just R studio but any IDE. The same issue appears on jupyterlab, Jetbrains IDEs, jupyter notebooks. Its definitely an issue with google drive products (sync, file-stream) – Gabriel Fair Mar 12 '18 at 13:31
  • Are there any Google Drive bug reports we can all chime in on? – randy Sep 03 '18 at 00:52

5 Answers5

10

EDIT: On further use of RStudio my solution didn't solve it - The sync popup just occurs at a lower frequency. The problem is that Google Drive currently doesn't have a feature to ignore Folders just filetypes.

--

This solved it for me:

  1. In Google Drive/Backup and Sync go to Preferences...
  2. Under My Computer click Change:
  3. Under Ignore files with these extensions add .rproj.user

See screenshots below:

Step 1

Step 2

Step 3

Oliver Oliver
  • 2,057
  • 4
  • 16
  • 14
  • I'm going to try this, but this looks excellent! I'll get back to you. I ended up switching to Dropbox out of frustration (even though i had more space w/Drive). If this works, I may switch back! – jpm_phd Apr 10 '19 at 18:17
  • 5
    Actually it didn't solve it - I keep getting the popup but at a lower frequency. – Oliver Oliver Apr 11 '19 at 01:02
  • This ignore option is no longer available (as Aug 2023, but maybe as early as Jan 2023) – Eduardo Zanette Aug 10 '23 at 15:47
7

I also have been having this problem for a long time. The simplest solution is to quit/turn off GoogleDrive when working in RStudio. You are not going to have ongoing backups but it is not such a huge issue anyway. You can still sync to your drive during the lunch break or after the day. This might solve also the other issues that many people are having. All-in-all GoogleDrive is probably not the best backup solution. I think having the Drive just for e-mails and random shared documents (15-100 Gb) is still a good idea but for serious backing-up (at least 1 Tb) probably DropBox or some other solution is preferable.

Pekka
  • 110
  • 1
  • 4
  • 1
    Resuming Google drive after a day's work in Rstudio reverted the files to the old copies on Google Drive for me. I saw this on a different computer. Luckily the originial Rstudio was open and I could Ctrl-Z to get back my edits. – highBandWidth Feb 14 '19 at 16:52
  • 1
    I ended up switching to Dropbox. – jpm_phd Apr 10 '19 at 18:17
  • Sadly, I had to switch from Google Drive to Dropbox. – jpm_phd Oct 23 '19 at 16:33
  • 1
    @user7698 I am using DropBox and I still have this issue. It seems not to be a GoogleDrive issue-only issue, but a more general sync software issue. – Miao Cai Jan 18 '20 at 03:23
4

I am not sure what caused this error, however I was able to resolve it by following the below steps :

Say you have got a file called temp.R which is giving you the error.

1) Copy all the contents of temp.R and create a new file on your local drive (anywhere outside Google drive) and paste the contents there. Save it with some name say demo.R

2) Now close temp.R from RStudio and move demo.R to google drive folder and now open it via RStudio file explorer.

You can now use demo.R as your new file and start working on it. It will also save all the changes you make henceforth.

So basically, we are just creating a new file and replacing it with the old one.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
3

In addition to Oliver Oliver's answer, you may also want to add .Rhistory to Gdrive's list of things to ignore. Basically any file that's being updated as you type/work without explicitly saving has potential for a clash. I'd also add .DS_Store if you're on OSX.

Benbob
  • 328
  • 2
  • 4
0

This is not the OP's problem, but for those who are still scratching their heads, an RSelenium run may leave an orphaned Java process behind and cause the same error message via Rscript on the command prompt. How can you tell? Try deleting the .R file in question. It will say

The action can't be completed because the file is open in java.exe

For a related issue, see https://github.com/ropensci/RSelenium/issues/228.

Kim
  • 4,080
  • 2
  • 30
  • 51