Dropbox conflicts with .Rproj.user

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