Content of .R scripts constantly deleted on onedrive (MAC) when closing and reopening

Hi all
I have been encountering a problem with my Rstudio lately. I run Rstudio on my Macbook and the Rprojects are located on my Onedrive (that syncs the file). However, since a couple of months, it keeps deleting the content of the file (not the file itself) so I lose all the information I have spent hours working on. My problem is similar these three posts: Content of .R file deleted - not the file, but the content and RStudio and Microsoft OneDrive and sometimes I have this problem How to remove a script from RStudio. I saw in one of the post that you recommended running an diagnostic report and it looks like there are a lot of errors. See a few here:

15 Jul 2021 01:48:45 [rsession-username] ERROR Unexpected exception: boost: mutex lock failed in pthread_mutex_lock: Invalid argument; LOGGED FROM: void rstudio::core::(anonymous namespace)::LockRegistration::refreshLocks() /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/core/file_lock/LinkBasedFileLock.cpp:227
16 Jul 2021 14:44:34 [rsession-username] ERROR system error 2 (No such file or directory) [path=/Users/.../.Rproj.user/B7E2B17A/sources/s-15EC60DB/A55EC61A-contents]; OCCURRED AT: rstudio::core::Error rstudio::core::FilePath::open_r(boost::shared_ptrstd::istream *) const /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/core/FilePath.cpp:1107; LOGGED FROM: rstudio::core::Error rstudio::session::source_database::get(const std::string &, bool, boost::shared_ptr) /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/session/SessionSourceDatabase.cpp:656
16 Jul 2021 14:44:34 [rsession-username] ERROR system error 2 (No such file or directory) [path=/Users/.../.Rproj.user/B7E2B17A/sources/s-15EC60DB/4102FD5-contents]; OCCURRED AT: rstudio::core::Error rstudio::core::FilePath::open_r(boost::shared_ptrstd::istream *) const /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/core/FilePath.cpp:1107; LOGGED FROM: rstudio::core::Error rstudio::session::source_database::get(const std::string &, bool, boost::shared_ptr) /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/session/SessionSourceDatabase.cpp:656
16 Jul 2021 14:44:34 [rsession-username] ERROR system error 2 (No such file or directory) [path=/Users/.../.Rproj.user/B7E2B17A/sources/s-15EC60DB/51BE6FC4-contents]; OCCURRED AT: rstudio::core::Error rstudio::core::FilePath::open_r(boost::shared_ptrstd::istream *) const /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/core/FilePath.cpp:1107; LOGGED FROM: rstudio::core::Error rstudio::session::source_database::get(const std::string &, bool, boost::shared_ptr) /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/session/SessionSourceDatabase.cpp:656

What is worst is that my onedrive keeps warning me that I have recently deleted several files. It sends me a constant reminder whenever I am working on R.
Any help would be greatly appreciated it. Thank you so much

Hi,

Although I do not have a real solution I have experienced a lot of issues with this myself and have come up with semi-explanation and a workaround .

What I think is going on: (not a very technical explanation :stuck_out_tongue: )
OneDrive tries to sync files as soon as they change on disk. This is to ensure that various syncing folders stay up to date. That's all very well when we're talking about regular files like a word document or an image, but RStudio both generates a lot temporary files (e.g. in hidden folders) and sometimes seems to lock several of the files depending on the situation. Locked files can't be synced, and sometimes the fast pace at which temp files are changed break the sync too. If you use git, even more hidden files are generated.

The reason I got a lot of trouble with it is that during developing and running shiny apps, OneDrive was going crazy trying to sync a lot of files and eating away CPU and breaking stuff. Again, since Shiny runs in the folder you're working on, it creates files on the fly.

Finally, the reason OneDrive complains you're deleting a lot of files is because this is a safety measure they use to help people prevent deleting folders with a lot of files by accident. Again, the files that are deleted in this case are all the temp files in the hidden folders that we don't care about, so the warning is useless and annoying.

How I avoid the issues: (not a solution)
I've written a little (batch )script in Windows that I call when I click a fake RStudio icon. It will automatically shut down OneDrive before starting RStudio. This way there is no syncing when I'm working in R. I haven't found an easy way for the same script to detect when I close RStudio, so for now I manually start OneDrive again when I close R.

This approach is not perfect, but I no longer have syncing issues and do not get the warnings for deleting too many files.

Hope this helps,
PJ

I use GoogleDrive instead, but the issue with syncing the temporary files is the same. My solution was to use Insync, which lets you exclude files and folders. I have it ignore .Rproj.user and it has worked perfectly. Insync supports both GoogleDrive and OneDrive.

1 Like

Thank you so much @pieterjanvc. It is a relief to know that others have experienced it too and that there might be a solution for it. I will give it a try

Thanks @EconProf . Will check out insync. It sounds promissing too

Hi @EconProf , it may be better to consider using Git (on GitHub or Gitlab) to maintain your scripts backed up. RStudio has a great integration with Git, it will also allow you to keep track of changes to your code over time, and you would avoid automated file sync issues, like you are having today, because you have to "manually" commit changes the to your files.