6

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?

1
  • This kind of thing is a major reason I use Github, even for personal projects. Jan 14, 2017 at 4:06

2 Answers 2

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

11

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.

8

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.

3
  • I had a few more links for you, but couldn't add more than 2 links to my solution due to being new. Best of luck!
    – user4458796
    Jan 15, 2015 at 18:28
  • Thanks I'll go ahead and try your suggestions. The strange thing is that the file looks untouched in that it is exactly the same size as before, 50KB, and it says that the last time it was modified was when I saved it before restarting...
    – user6893
    Jan 15, 2015 at 18:41
  • Could the text format been changed? e.g. utf-8 to something else?
    – Alex
    Jan 16, 2015 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.