How do I open an r script (.R file) in RStudio by double-clicking it in windows - r

When I double click an R script (.R file) in order to open and edit it, nothing happens.
I expect it to open it in either R or RStudio but it doesn't.
I found a similar (old) question (Opening a .R file via a double click (Windows)) but the solution doesn't work for me.
I have tried:
- right-clicking and explicitly telling it to open it with RStudio
- set it as the default program to associate with this file type
- drag the script into RStudio
Anyone any idea whether it is Windows or R(Studio) related?
Running:
Windows 10 Pro
R version 3.6.1
RStudio version 1.2.1335

As the first comment suggest, it is likely a problem occuring while installing R or Rstudio. This would most likely be fixed by reinstalling Rstudio. If it doesnt i'd suggest checking out this Rstudio question.
Basically, you can manually create using the command prompt (start -> "cmd" -> enter), using
assoc .R=rfile
Ftype rfile="C:\Program Files\RStudio\bin\rstudio.exe" %1
changing the rstudio directory to the correct directory for your computer.
A less command-prompty solution might be available by following the steps described in this guide. However i did not test the latter approach.

Related

After updating R the code is not displayed anymore

So, I updated R using the installr package in the Rgui. Now I face two problems:
My previously written code is not displayed anymore - the file is not empty, I checked it by opening the file with the editor. Opening the file by regular double clicking (RStudio is default application) as well as open the file within Rstudio by using File -> Open File -> Filename did not help. It does open the file but shows it as an empty file (no code is displayed).
When loading packages, I get the request for updating my RStudio. But when I use the taskbar (Help -> check for Updates) it says, that the RStudio uses the newest version.
After updating I also restarted my computer, which did no help. I also checked if the newest version is actual in use as suggested in the following post Mismatch Versions.
Any idea what I am doing wrong and how to display the code again? Thanks!
Update: The problem was solved by installing the newest RStudio version directly from their website.
Meanwhile, I found the solution - the true root of the problem was in fact an old version of RStudio. Besides in RStudio it was declared as the newest version, here it was mentioned that these statements are not always correct.
Downloading the newest version directly from the RStudio website solved the problem.

R plot doesn't work on my Windows, but plot.default does

I'm taking a course in R and I've hit a road block on day one.
Typing:
demo(graphics)
...should start a series of graphs being displayed on screen. On my Windows 10 (64 bit) new Dell laptop, I get a persistent error:
The execution is stopped after the red lines, seemingly because the demo(graphics) call is being made with incompatible parameters. In blue I make the same call but use the default function and an empty plot is displayed.
I have tried uninstalling and reinstalling everything, installing through Anaconda and from the CRAN website. The same error persists. I've even tried with mro instead of basic R.
I don't see any similar error messages in my class or on Google. My guess is that I need to install a particular version of R and RStudio make it work but I'm guessing.
Can anybody offer some expertise?
I'm running R version 3.6.1 (2019-07-05) (which is executing code correct, just not the demo call) and RStudio Version
Running the basic Rgui software from the command line with the --vanilla parameter like so:
Rgui --vanilla
Opened Rgui and the
demo(graphics)
...call worked.
This meant that the issue was in the .Rprofile file. This is found in the etc folder of the basic R installation and when I checked, it looked absolutely fine (entirely commented out actually).
I wanted to use RStudio though, so I investigated the RStudio docs and saw that each project is given its own .Rprofile style initialization file when a new project is created.
So I created a new project with RStudio and by creating a new project whatever configuration issue was causing the error was completely fixed.
Credits to G. Grothendieck for the answer in the comments.

new version of R with rstudio

I installed a new version of R but rstudio still uses the old version. The command "which R" is just a shell script and I'm not sure how to get rstudio and the new version of R integrated. R base installed in /usr/share/doc.
Any tips?
Thanks,
Bob
See the RStudio support pages. In particular, for Linux, you have to set the RSTUDIO_WHICH_R environment variable.
As found out in the comments, you're on a Linux system, specifically Linux Mint 17. I can see three basic scenarios here:
You want to ensure RStudio uses a specific version of R when you are launching RStudio from the terminal as a one-time event.
You want to ensure RStudio uses a specific version of R every time you launch RStudio from the terminal.
You want RStudio to use a specific version of R when you launch RStudio from the applications menu (or, equivalently, via something like Synapse).
They are dealt with in turn below. I assume throughout that the path to the R binary you want RStudio to use is /opt/R/3.1.0/bin/R, which you should change as appropriate.
One-time Terminal Launch
After opening a terminal via Ctrl-Alt-T, run
export RSTUDIO_WHICH_R=/opt/R/3.1.0/bin/R
Then, anytime you launch RStudio from the terminal via the rstudio command in that terminal session, it will use the specified R version. However, after you exit, the next time you open the terminal, it will no longer respect that choice.
Every Terminal Launch
Use your favorite text editor to edit the file ~/.bashrc. At the end, on a new line, add
export RSTUDIO_WHICH_R=/opt/R/3.1.0/bin/R
Then, either launch the terminal, or if you already have it open run the command source .bashrc. Then, you can launch RStudio via the command rstudio and it will use the version of R you want.
Launching from the Applications Menu
Use your favorite text editor to edit the file ~/.profile. At the end, on a new line, add
export RSTUDIO_WHICH_R=/opt/R/3.1.0/bin/R
Then you need to log out of your system and log back in. After that, anytime you launch RStudio from the application menu, it will use the specified R version.

Passing argument to R with Command Prompt [duplicate]

I'm exploring package building on Windows 7 but have been running into trouble after reaching the Command Prompt stage. The following thread appears to be on the same topic that I'm having trouble with, but the question remains unresolved:
Cannot install R package in Windows 7
The problem: whenever I try an R CMD command in Command Prompt (e.g. I've tried R CMD install pkgName, R cmd install pkgName, Rcmd install pkgName, where pkgName is a place-holder for an actual package that has been R CMD checked on OS X and also posted on CRAN, where I have the unzipped source in the current working directory), I get the following error message:
'R' is not recognized as an internal or external command,
operable program or batch file.
(If I try the Rcmd install pkgName command, then the error starts out as 'Rcmd' is not ....) Note that even if I type in just R in Command Prompt and hit enter, I get the same error, so I'm not even able to bring up R here, though it opens perfectly fine in its stand-alone interface.
I have examined the following guides without success in identifying the trouble:
Karl W Broman's website
Rob J Hyndman's website
Steven Mosher's blog
The most immediate thing that came to mind was that the path variables in Windows were not set right, but this also has not (yet) led to the answer. For example, I have triple-checked the paths to ensure they are correct, including for the R version number, that x64 in the path name is accurate, etc.
I realize this is a complex issue to remotely diagnose, but any advice and suggestions on resolving this trouble is appreciated. For reference, below are the steps I have taken already to try to resolve this issue:
Uninstall R and Rtools
Install the latest version of R (2.15.0)
Install Rtools215 to match R version 2.15.0
Originally I let Rtools specify the path variables (turning that option on during installation). No success after this method.
I updated the path variables on my computer, where the below paths were used:
C:\Rtools\bin; C:\Program Files\R\R-2.15.0\bin\x64;
I've also tried the R CMD (and Rcmd) commands with the following paths included (note that these paths don't lead to anything on my computer, so I tried doing R CMD / Rcmd with and without them specified):
C:\Rtools\perl\bin; C:\Rtools\MinGW\bin;
Tried adding/removing the following path, which goes to the only other folder visible within the Rtools folder:
C:\Rtools\gcc-4.6.3;
Tried multiple variations of the R CMD commands, as noted earlier.
I tried this all a few months ago when I had R version 2.14.1 and Rtools214 installed, and I had the exact same trouble.
Note: I already had Cygwin installed prior to R and Rtools, and I have not installed MikTeX (yet).
Have you closed the command prompt and opened a new one after adjusting the PATH?
Enter the command PATH on the command line and ensure that you are properly updating your path
Try navigating to the directory where R.exe is saved and running it locally -- cd C:\Program...\bin\x64, R.exe.
Ensure that you're running on Windows' Command Prompt and not Cygwin's terminal
If you actually have a space after the semi-colon in your PATH, you'll need to remove that: /bin;C:/Program.... Try combining that with Joshua's solution.
I attach my whole solution here:
Install Rtools which is compatible with my R version
Add PATH: C:\Program Files\R\R-2.15.1\bin\x64;C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin
In cmd, enter: R CMD INSTALL packagename
Click "enter", done.
I had a lot of trouble getting this to work, and finally found the golden nugget on r-project (R doesn't like spaces in paths) so here's how I finally did all this:
I installed R to "c:\programs" instead of "c:\program files...". My final path to RSCRIPT.exe is "C:\Programs\R\R-2.15.2\bin\Rscript.exe"
I added that directory to my PATH, but that doesn't seem to help
RStudio is also installed under c:\Programs (e.g. c:\Programs\RStudio), but RTools is installed under the "c:\" root directory (e.g. c:\RTools).
I downloaded all the packages to "c:\downloads\r"
I opened a command prompt in "c:\downloads\r" and ran the R CMD install from this downloads directory, specifying the path to R
e.g. "C:\Programs\R\R-2.15.2\bin\x64\R CMD INSTALL colorspace_1.2-0.zip"
It appears that the CMD processor is Case Sensitive. You have to use INSTALL vs. install
Simple solution, use quotes:
c:> "C:\Program Files\WinZip\wzunzip.exe"
if you run this, you don't need to worry about the space in Program Files.
Hope this help.
I encountered a similar problem while trying to use SparkR from Windows Power Shell. Each time I would do ".\sparkR.cmd" (I was inside the folder containing this file), it would throw an error message like,
cmd is not recognized as an internal and external
command...blah...blah...blah.
I solved the problem by adding "C:\Windows\System32" to my PATH.
I restarted my system and then repeated the process and this time, I saw a new error,
R is not recognized as an internal and external
command...blah...blah...blah.
I tried all sorts of approaches, including the ones mentioned above. NOTHING WORKED, I was probably wasn't efficient enough to make it work.
Then I came across this place at code.google. I simply copied the R.bat onto a notepad, named it as R.bat. Kept it inside the folder where sparkR.cmd was located. For me it was,
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\
The I placed it on my PATH as :
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\R.bat
Restarted my laptop, opened my Power Shell as an administrator and typed :
.\R.bat help
It worked fine. Then I typed,
.\sparkR.cmd
and there it was.
It worked.
I hope it helps to people new to R. Thank you G. Grothendieck.
In the .bat file add a line of code specifying the path of the folder where R is installed and then give the path of the script as follows -
#ECHO OFF
PATH C:\Program Files\R\R-3.5.1\bin
R CMD BATCH D:\project_abc\helloworld.R
Following this, run the .bat file and you will see the code in the script will run smoothly.
In my case the issue was solved by using Edit instead of New while selecting PATH in the window below:
enter image description here
After selecting Edit I added the directory below:
C:\Program Files\R\R-4.0.2\bin\x64
This solved the issue in my case.

RStudio empty on startup - No windows, no menus, no rendering

When I start RStudio, none of the windows inside the main frame come up, and none of the menu options display menu options when clicked. It's just an blank page.
It feels like some kind of graphics rendering or window management problem.
I'm running Windows 7. I have the latest version of R, which is 3.1.1. I have the latest RStudio, which is 98.1062.
How to fix it?
Reset the RStudio state. Do this:
Close RStudio if open.
Go to this directory: %localappdata%\RStudio-Desktop
Rename that directory as a type of backup.
Start RStudio.
RStudio will see the configuration directory is missing and regenerate it with correct values.
Everything should work after that.
Other threads I found helpful here are:
https://support.rstudio.com/hc/en-us/articles/200534577-Resetting-RStudio-s-State
https://support.rstudio.com/hc/communities/public/questions/200666647-RStudio-096-16-Windows-7-gives-empty-screen?locale=en-us
Thanks!
Renaming the RStudio state by renaming %localappdata%\RStudio-Desktop did not work for me. However i made it work by renaming another config folder in %appdata% instead.
Close RStudio
Go to this directory: %appdata%\RStudio
Rename the folder
Restart RStudio
I faced the same issue when I downgraded my version of R.
I did try the above solutions. However, it didn't work for me.
After some googling, I found out that the issue was because now I had a different version of R installed. Here's how you can choose the version of R and rectify the issue.
Navigate to the RStudio installation folder. (C:\Program Files\RStudio\bin)
Press and hold Control Key
Double click on rstudio.exe
Choose a specific version of R (whichever you want to work with)
Click OK and RStudio should open without any issues.
NB: I use 64bit Windows 8.1.
I had the same issue and I almost gave up about solving it but then I found a suggestion that GitHub might be the problem. I am not sure how that is happening but the minute I uninstalled GitHub and re-launched Rstudio, it worked perfectly as nothing happened!? Here is the link for where I found the suggestion on Rstudio community page: (https://support.rstudio.com/hc/communities/public/questions/200983187-R-studio-0-98-797-for-mac-opens-as-blank-white-page)
I had the same problem and figured out that for some reason R was blocked on the step of loading my library from a website (I added it to Rprofile for auto-load). You can test the following:
1) Try to run just R console, not RStudio, and then click on blank space - normally some information should appear
2) Try to launch without network connection
On a Mac (Running Yosemite 10.10.3) this is what worked for me:
Move/Rename ~/.rstudio-desktop
(Many responses have mentioned this, but this by itself didn't help.)
Then I shutdown my Mac and restarted it. RStudio worked when I logged back in.
Before that, I tried every one of the steps mentioned here and in many other links, including re-downloading R and RStudio, but unfortunately none of those steps helped in my case.
Search this documentation for 'Blank GUI'.
This is what I found which worked for me:
In Windows Explorer, go to C:\Users\currentUser\AppData\Roaming\RStudio.
Delete the Desktop.ini file
This technique forces RStudio to refresh and default to open-source R as the engine
Same issue I faced so I unistalled the windows installer and downloaded zip version from this link https://www.rstudio.com/products/rstudio/download/
Unziped It and pasted it into c drive and created shortcut from Rstudio/bin/rstudio.exe file.
Working properly after that no issue. In windows installer checked that r session is not working due to an missing dll.
So try to install from ZIP
I had the same problem like Thomas
When I start RStudio, none on the windows inside the main frame come up, and none of the menu options display menu options when clicked. It's just an blank page.
My problem was, that i uninstalled R because is thought RStudio will work on its own.
So i uninstalled RStudio and deleting every existing file which was created by R or RStudio.
In the next step i installed RStudio again.
It was asking for a Version of R (which i dont had in this state). So i installed R again and everything is working fine now. I hope this helps
I had a slight variation of the problem that might be of interest. I had set up an aliases.cmd to run my cygwin bash shell automatically upon launch of a cmd terminal as per:
https://superuser.com/questions/302194/automatically-executing-commands-when-a-command-prompt-is-opened
What RStudio was doing was launching a few cmd windows in the background to (I assume) populate each pane and the console.
This was triggering a bash shell which wasn't returning and was hanging RStudio.
If you have this issue you can just manually kill the sub bash terminals spawned by cmd via ProcessExplorer/TaskManager and RStudio will continue to launch normally.
If anyone else has set anything to launch automatically on init of a cmd terminal then this could interfere in the same way with RStudio.
The RStudio devs could probably fix this behind the scenes by changing the way they spawn cmd terminals in the gui.
I had a similar problem. After trying the options above with no luck, I uninstalled Rx64 3.5.0 and installed an older version, R x64 3.2.2.
Rstudio then worked perfect.

Resources