I have a number of R scripts saved on my work laptop. I updated the R version from 4.1.1 to 4.2.1 (most recent version) on this laptop.
When I tried to open the scripts on my work laptop after the update, they were ALL completely blank - even the ones I was not working on, nor even had open, at the time of the update. The script files themselves still exist and are said to contain data according to file properties (i.e: they aren't said to be 0kb), but when opened, there is nothing in them - no code, comments, etc.
I can see all the code again by opening the "blank" file, selecting 'reopen with encoding', and selecting 'UTF-8'. However, I have to do this every time I open the file, and it doesn't feel that 'secure'.
How do I fix this?
Related
I have used R for years and, until recently, have had few problems. However, since the last update, R keeps erasing scripts that I have saved in the Source window; then, when I go to retrieve them from recent files, it opens a script that has a title but zero code. I am able to open the files in notepad and copy/paste them back in, but I would like to know how to resolve this issue so that I could use R in the same expeditious manner as previous.
To reiterate with slightly different wording: R opens my saved scripts (.r files) as codeless source windows; there is simply a number 1 there and nothing else, though the title is displayed. I did save one as a text file and tried to open it that way but got the same results. Opening files in Notepad and copying/pasting them does work, but obviously R should be able to open R scripts and display R code.
Can anyone shed some light on this issue?
Thank you,
Matt
It's not sophisticated, but I would
uninstall R & RStudio
reset/remove the "internal state" stored by RStudio
reset/remove the "preferences" stored by RStudio
reinstall R & RStudio
Here's good documentation from RStudio for points 2 & 3, depending on your version and OS: https://support.posit.co/hc/en-us/articles/200534577-Resetting-RStudio-Desktop-s-State
My RStudio is opening multiple processes(opening R Studio in different windows) when I open just one. I am not able to open any project. It becomes unresponsive. I tried using in compatibility mode, running as admin and also uninstalled. But still,(here's the image) the same problem persists. Can someone please help me?
Before you reinstall everything, which may take a lot of time, it is worth removing application data, which is a cache R keeps of last sessions etc. It involves settings such as information from last session, etc which RStudio tries to reopen every time you open it.
For app data, look under your user folder which must be somewhere like
c:\Users\<your_user_here\AppData\Local
c:\Users\<your_user_here\AppData\Local\LocalLow
c:\Users\<your_user_here\AppData\Roaming
Delete every subfolder called R, RStudio-Desktop or RStudio under these folders. Don't worry, you won't lose your source program files and projects. It may help you recover everything without having to start over from scratch.
I have recently started using R for uni. I want to save my code using either save as or ctrl+s. However, the saved file is empty more often than not. For some reason, the files save normally on a few occasions. However, they also became empty after saving changes to the script.
I couldn't find any solution for the problem, neither here nor anywhere else.
I am using RStudio installed via Anaconda on an Windows 10 x64 Notebook, if that helps.
Thanks a lot for the responses! I'd be glad to provide more details if needed!
This is what the saved files look like from File Explorer:
I just meet the exactly same problem. I solved it by checking and changing RStudio -> File -> "Save as Encoding" from "ISO-8859-1 (System default)" to "UTF-8", then the file was saved. I'm trying to recover my previous 0kb files...
i couldn't reproduce the error but i also don't like to use the anaconda environment.
if the problem is saving the text file than may i suggest to do just that and save the code in a regular .txt file?
if this is not an option you can try to find out what happens if you save the r studio code on a different drive (or usb/flash drive)
###########################################################
EDIT 14.07.2022
Interestingly enough, just today (14.07.2022) I had the same problem. After installing R 4.2.1 everything worked fine until I changed the encoding (from utf-8 to windows 1252), at which point all the files in my project were overwritten and are now empty. Changing back to an older version of R (4.1.3) allowed me to display/save/use all scripts again (from backups).
Using the answer provided by #Shidan it is possible to open the data in R-4.2.1 as well.
This problem does not seem to be connected to Anaconda but an encoding issue between Rstudio and any R distribution above (and including) 4.2.
I am repeatedly getting the error message:
Error Save File: ' The device does not recognize the command' popping up over and over (every 15 seconds) - even when I don't click save or when I do click save.
I also can't load a R file that is in my folder - I have to open it up in notepad and copy it paste it to even see it.
Can someone let me know how to fix this? I have the latest version of Rstudio installed.
This happens when the drive memory runs out of space. As a quick fix measure, try copying all the code to an another R script file/ notepad and you might save it luckily. Long term solution would be to clear the cache and upgrade your hard drive..
This can also happen if you are reading from a file that is open in another program in some cases. Generally speaking R has no issues reading in files that are open / read only (i.e. import a CSV file) if that file is in use by another process. However, there are some cases where the read-only restriction from a locked file being imported causes the
Error Save File: ' The device does not recognize the command'
message to persist even if you are not trying to to read from or write to the locked file.
As a specific example, if you are using openxlsx to import an xlsx file that you are also viewing in excel, after reading the xlsx file in, you will get the error whenever you make changes to your R script and stop for more than a few seconds, or when you try to save the R script, even though it is not touching the xlsx file. However, if you close R Studio and re-open your script, you will notice that the issue will not appear until you try to read the xlsx file in again.
Met error "The device does not recognise the command" today. Not due to disc space but due to an r script that was somehow no good, even though file extension OK. After a very frustrating time when I couldn't copy to a fresh R script or shut down the project, saved content of troublesome r script to another older r script, deleted it and all OK - e.g. could now open up another new script that saved with no problems.
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.
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?
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.
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
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.
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).
Use a Hex or sector editor to try to recover the data.
Use a data recover program to find an old version of your file.
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.
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:
Use version control. Git is supported in RStudio's GUI interface.
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.
Make backups. Distinct from #2, you should backup your files to a hard drive, flash drive, or cloud service like Dropbox or Spideroak.