RStudio not opening a script - r

I've got an issue with my RStudio IDE. It currently won't open a pre-existing script file.
When I select it for opening it will open up a new script tab with the given name of the script I want but without any contents.
Also, when I open up the script as a text file the contents are present and intact.
Any ideas on what I need to do to get Rstudio to properly read my script?
Thanks

Related

R Studio will not open .r files in source

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

Can't save an R scirpt as an R file

I use R Studio on a Windows Computer.
I have a problem with saving R scripts as an R file. I tried to click on "save as" and then give the file a name ending on .R, but it doesn't save the file.
I then find a file with this name on my computer, but it is empty (0KB) and shows nothing when I open it. The whole code is gone.
How can I save an R script properly? What could be the problem? Thanks a lot!

Unable to save R script as an R file

When trying to save a script as an R file, I am not able to. The save as window opens, but the 'save as type' bar below the 'file name' bar is blocked/greyed-out. I am, however, able to save the script as an unreadable file. When I open it again to continue working on it, it cannot run. I then have to copy paste it to a new script to continue working on it and running the commands. I cannot seem to find many questions on the internet relating to this problem except this one: https://support.rstudio.com/hc/en-us/community/posts/219163988-Can-not-save-new-R-script-save-as-bar-grayed-out.
I have tried save() which does not work. I have also uninstalled R and installed the latest version of R, this does not help either. Would anyone know how to fix this problem so that I can save it as an R file?
EDITED:
I am using RStudio version 3.4.4. on the Windows 10 Home edition.
Processor: Intel(R) Core(TM) i5-7300HQ CPU # 2.50GHz.
RAM: 8.00 GB.
System type: 64-bit Operating System, x64-based processor.
Many thanks
friend!
I had the same problem as you. But what resolved was just put ".R" (example: save.R) in the end of the name, even with the grey bar, it generated the script automatically.
Hope it can help.
Windows 10 now prevents Rstudio to save a new document.
Give Rstudio permission, restart it and than it worked for me.
These other answers don't solve it for me. What I noticed is:
Working off of a network drive is a nightmare for R Studio.
Even if you do save it as an .R file, R Studio may not be able to open it.
What I did was:
Paste my script into a notepad file; save it as .R
Right click my .R file and Open With RStudio.
This minimizing RStudio doing the driving of opening files. And once the file is NAMED (it was named and saved as .R in notepad) RStudio seems to be able to save/overwrite changes to the file. It just cannot save the file the first time nor save TXT files it opens as .R files.
So yeah, for the initial script; template it in notepad and never change it's name.
By saving the R script with .R at the end automatically saves it as an R file!

RStudio error message - the device does not recognize the command

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.

How to easily open a script in R-studio

I am very new to R-studio. In RGui, I was used to click File / Open Script to open a new script. But in R-studio, I only see File / Open File which generaly opens any file (?). The disadvantage is that I have many files in my directory and I want to see only *.R files when opening a script - which is what Rgui does and I love it - but cannot figure out how to do the same in R-studio.
If you use windows, you can just type
~>".R"
into the search box top right (while you are in your R folder), and you will only see files that end on .R
If you click into the search box, you see your past search queries, so you won't have to type it again every time you open a script.
If you use a different OS, look for a respective search "wildcard".
edit: "show file extensions" should be activated

Resources