user6893
user6893

Reputation: 143

RStudio R File Corruption

I had a R script open in RStudio. The file was saved many times over the course of several weeks and worked perfectly fine when RStudio was opened and closed. However, today, I restarted my computer and when I opened RStudio and more specifically the script that I mentioned, all of the R code vanished, leaving a single long row of "....." with red highlighting.

enter image description here

When I tried to open the R file in other text processors such as Sublime Text and Notepad++, only a line of zeroes was visible. None of my other R files were affected. I'm currently running Windows 8.1 and have the latest version of R and RStudio. What can I do to recover the code in the file and prevent something like this from happening again?

Upvotes: 7

Views: 9102

Answers (2)

Ben
Ben

Reputation: 152

It might be an old thread and it might have been covered in 'user4458796' answer in suggestion #1 ("Use the history..."), but:

My friend had the same problem and we managed to recover the code from a 'history_database' files located on Windows at: 'C:\Users\%user%\AppData\Local\RStudio-Desktop\'

I assume there is an equivalent location in Linux in general.

Hopefully I won't get downvoted, just sharing my 2cents.

Ben.

Upvotes: 12

user4458796
user4458796

Reputation:

It's not clear what happened to corrupt your file (and thus how to fix it if possible) and it is kind of ominous that you're just seeing 0's in other text editors, but I'll give you my best suggestion and some tips.

Suggestions for Attempting Recovery

  1. Since your other R files were unaffected, you should have a messy record of your code in the history. Use the history to reconstruct your code.

  2. Access a copy of your file from any version control, cloud, or offline backup you may have used -- git, SVN, iCloud, SugarSync, Dropbox, etc (I realize you probably wouldn't have posted this question if that were an option, but I had to throw it out there).

  3. Use a Hex or sector editor to try to recover the data.

  4. Use a data recover program to find an old version of your file.

  5. Inspect your trash or recycling bin to see if it has an old version. Depending on your OS and the settings of how you (insecurely or securely) delete files, then you may be able to undelete a deleted version, even if it's not immediately available.

  6. Try different methods of recovering text data from corrupted text files like OpenOffice's and Microsoft's suggestions.

Tips for the Future

I know that hindsight is 20/20, but a few quick tips for good measure:

  1. Use version control. Git is supported in RStudio's GUI interface.

  2. Have more than one version of your file. Many professors and professionals recommend writing/storing code in a text editor and using your IDE only for the working copy.

  3. Make backups. Distinct from #2, you should backup your files to a hard drive, flash drive, or cloud service like Dropbox or Spideroak.

Upvotes: 8

Related Questions