Dropbox conflicts with .Rproj.user

Hi Rstudio Community,

So this seems like an ongoing issue with Rstudio and Dropbox. I run all my files including all of my Rprojects off of Dropbox. However, while running a session a consistent error pops up which is super annoying. The error message is the following Save File "The process cannot access the file because it's being used by another process". The error message is a result of Dropbox trying to consistently sync the .Rproj.user hidden folder which is actively being updated during a session.

Rstudio currently has this resolution on their website which consistently says it's up-to-date however this work around doesn't work and you can't comment on the actual issue, see here. Additional posts regarding this issue can be found here, here, and lastly here.

The only alternative is to stop syncing while the session is running however this poses multiple hindrances as I run different sessions on different computers and have results and figures being produced and want them synced to Dropbox as soon as they are created so I can access them on different computer e.g. see the results of the GAMMs that I'm running on a different computer then it was run on.

Anyone have any suggestions or ways around this?

Thanks,
Ben

3 Likes

Hi there,
I discovered that Dropbox have a new feature in beta, where individual files and directories can be excluded from syncing:
https://help.dropbox.com/en-US/files-folders/restore-delete/ignored-files

So, I gave it a try on my Windows 10 machine using shell() to send the required commands to powershell. It does seem to work for the Project directory (not sure about the project file) - the directory icon changes to have a "minus" symbol, and the error messages seem to stop. You can also experiment by blocking syncing for any other file you choose.

Anyway, here is the code I used which you may be able to modify for your situation.

dropbox_project_sync_off <- function() {
  require(usethis)
  this_project <- usethis::proj_get()

  if (grep("Dropbox", this_project) == 0) {warning("This project is not in a Dropbox folder")}

  dir_to_block <- paste0(this_project,"/.Rproj.user")
  file_to_block <- paste0(this_project,".Rproj")

  dir_to_block <- gsub("/", "\\\\", dir_to_block)
  file_to_block <- gsub("/", "\\\\", file_to_block)

  # Powershell command examples:
  # These set flags to prevent syncing
  # Set-Content -Path C:\Users\myname\Dropbox\mywork\test\test.Rproj -Stream com.dropbox.ignored -Value 1
  # Set-Content -Path C:\Users\myname\Dropbox\mywork\test\.Rproj.user -Stream com.dropbox.ignored -Value 1

  s1 <- paste0('powershell -Command \"& {Set-Content -Path ', file_to_block, ' -Stream com.dropbox.ignored -Value 1}\"')
  s2 <- paste0('powershell -Command \"& {Set-Content -Path ', dir_to_block, ' -Stream com.dropbox.ignored -Value 1}\"')

  shell(s1)
  shell(s2)
}

dropbox_project_sync_off()

HTH

4 Likes

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