0

I just cleaned temporary archives of my pc (Windows 10), when I opened RStudio again my script was empty. The file exists and it's still in the place I saved it. But it only has 1 line and it's empty.

This is how my scripts look

Is there any way to recover my files?

starball
  • 20,030
  • 7
  • 43
  • 238
biomanu
  • 11
  • 3
  • RStudio has an autosave function, see https://www.rstudio.com/blog/rstudio-1-3-the-little-things/. If that is not enabled, you might find something in `%TEMP%`, but I tend to doubt it, in which case I hope you have a backup somewhere. Now might be a good time to revisit where you store files, what Windows thinks are "temporary archives", and/or some form of backup strategy (even if it's a thumb-drive you copy files to periodically). – r2evans May 11 '22 at 20:15
  • (And you may want to enable autosave.) – r2evans May 11 '22 at 20:24
  • If nothing is found, little of the above is going to save you this time, you will likely need to recreate your code. However, good practices need to be started before they become necessary. It would also be a worthwhile venture to consider version control (e.g., `git`), which RStudio supports immediately. (In my case, version control saved my graduate research, allowing me to find when something I needed was inadvertently changed, and then restore the then-working version.) – r2evans May 11 '22 at 20:26
  • It seems that it is a problem with R or RStudio ability to read scripts, as I just download an script from the internet and it appears the same @r2evans – biomanu May 11 '22 at 20:43
  • Then I'd suggest re-installing RStudio. – Gregor Thomas May 11 '22 at 22:35
  • Done, it hasn't work either, now i know the problem aren't the files, send them to another computer and they appear normal... (except one) @gregorthomas – biomanu May 12 '22 at 02:47
  • See solution here - https://stackoverflow.com/questions/72096770/problem-with-opening-scripts-in-updated-version-of-r -- this worked for me. – praneeth kandula Jun 01 '22 at 16:56

2 Answers2

1

Apparantly it is a problem with the encoding, so to solve it you must open the script and then go to files > reopen with encoding

biomanu
  • 11
  • 3
0

This was most likely the following upstream bug of RStudio, which appeared, when using R 4.2 in connection with affected RStudio versions. https://community.rstudio.com/t/r-code-file-is-becoming-0-kb-after-saving/138585

hannes101
  • 2,410
  • 1
  • 17
  • 40