Unable to run edit() command in RStudio - r

I have just started out on R and have hit a roadblock. I can't seem to run the edit() command in RStudio.
Here's what I have tried
1. Changing the RSTUDIO_WHICH_R environment variable
2. Fixing the warning messages which were displayed every time I opened the RStudio.
3. I have even reinstalled R and RStudio.
I have posted the image of the error message that I get on my Console window.
I am working on MacOS High Sierra
Any help is appreciated.
I have installed Xcode as well and the error has changed as shown in the second image.
Error Message after installing Xcode

You may be missing or have to reinstall XQuartz 2.7.11, install it first then try running edit command.If it doesn't work then do the following.(This happens sometimes during an update)
1) Find the location of libcario.2.dylib using locate command from terminal/iterm-2 . Use command locate libcario.2.dylib, you should receive something similar with this location: /usr/X11/lib/libcario.2.dylib. Someone can use cd,find to locate the location as well.
2) If the location is found then use ln -s to create a link like below:
sudo ln -s /opt/X11 /usr/X11

Related

devtools::install_github("imbs-hl/ranger") fails - make.exe and sh.exe unable to start correctly

I'm trying to install the development version of the R library ranger from RStudio on Windows 7 with the command:
devtools::install_github("imbs-hl/ranger")
When I try this, I first get a pop-up with the header "make.exe - Application Error" and the message "The application was unable to start correctly (0xc000007b)."
I then get a message saying that I need to install additional build tools. This downloads RTools. I then get an identical pop up like the make.exe one, except that this time it's for sh.exe. After I click ok, it then does a somewhat long install of RTools. The setup window closes and the development packages remain uninstalled.
Note: when I run either sh.exe or make.exe from the windows command line, I get the same errors. This might have something to do with the fact that I have cygwin installed.
I can get sh.exe and make.exe to run from the windows command line if I remove RTools from the path, leaving only cygwin. However, this doesn't change the problem I get when I try installing the development version of ranger.
Any help would be appreciated.

Running R from Mac OSX terminal

I've searched the web, and I'm still unclear on how to run R from the Mac terminal. I have Rstudio and the standalone R app installed. I thought I could just type "R" from the command line as I do with "python", but that doesn't work. Is it necessary to edit the PATH in my bash profile? If so, how do I give the correct location of R?
Thanks for any help
Edits after receiving comments
So, I'm running Sierra, and when I type "r" or "R" at the terminal, I get "-bash: R: command not found." If I type, "which R" in the terminal I do not get any output.
Here is the output from "echo $PATH": /usr/local/heroku/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/samuelcolon/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/samuelcolon/.rvm/gems/ruby-2.1.0/bin:/Users/samuelcolon/.rvm/gems/ruby-2.1.0#global/bin:/Users/samuelcolon/.rvm/rubies/ruby-2.1.0/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/samuelcolon/.rvm/bin:/Users/samuelcolon/.rvm/bin
As for the installation, I believe I downloaded it directly from cran.r-project.org a while ago. I can locate the GUI in my applications and open it--
I have version 3.13. Is it possible, I only have R.app installed but not R? Perhaps that's the reason I'm getting the 'command not found' when typing "R" into the terminal?
Generally, I've been working in RStudio, but I'd still like to access R from the terminal and also to find where things are located. I'm fine with removing and re-installing R if it's easiest to start from square one. I hope the extra detail helps, and I appreciate the responses.
An answer for those not that familiar with Terminal and Bash.
I have done a fresh update install of R from the R.org cran site as part of seeking an answer to your question.
I found this latest install version 3.4.0 installs R for access in Terminal, and also installs R.app as part of the package.
To my understanding, reading support docs, if you have an older version of R it will update that. However it will not update an installation of R installed by the anaconda package.
Where are the R files stored?
I can only assume that with a fresh install of the latest R, R will work for you in Terminal.
To learn where the R files are that are being accessed - in Terminal after starting R, and in R.app, type:
>R.home()
In my case as example:
In R.app - the R version 3.4.0 is accessed in the top directory (not my user folder):
R.home()
[1] "/Library/Frameworks/R.framework/Resources"
In Terminal - the R version 3.3.2 is accessed in the Anaconda package, again in the top level directory.
R.home()
[1] "/anaconda/lib/R"
So I have two different versions of R, and Terminal accesses a different version to R.app.
How can I ensure I access the same version in Terminal as I do in the R.app?
For someone familiar with bash, and how the whole bash command system works I am sure there is a well constructed command. All the same here are some novice solutions.
-
• First Solution:
I could update the anaconda version, however, I would prefer not to as as other elements of the anaconda package my depend on this older version of R. For those not yet familiar with Terminal and bash, not such a novice solution.
-
• Second Solution:
This solution came from mko. It provides a single use solution. From the result above, and checking the directory structure a little further to find this R file.
Finding the significant R file enables me to edit an extension of the above path shown in the R.app. So add /bin/R to enter
/Library/Frameworks/R.framework/Resources/bin/R
Entering and pressing return will start R from this version.
Alternatively, one can find this file and icon in the GUI Finder, lead by the above result, and just double click on it, and it will open Terminal and a session with R running for you. Easy!
One could also make an alias of it and put it on your desktop for easy future starts.
-
• Third Solution:
My last solution I think may be best, adding to mko's solution. Make an alias.
Being in my home directory in Terminal I open .bash_profile using the nano text editor. (If you do not already know how to do this, then best not use this solution.)
I then add the line in this env file.
alias Rv340='/Library/Frameworks/R.framework/Resources/bin/R'
I then save the changes and exit this terminal session. I then open a new Terminal window. (This is so the changes to the env above are incorporated in the new terminal session).
Then when I enter the alias:
Rv340
The version of R I want opens.
You can choose a different alias name to "Rv340".
-
• Fourth Solution:
A second more permanent solution for opening the same version of R in Terminal is as follows.
Copy the path as showing in R.app in response to the R.home() command above, and add that path to PATH in your .bash_profile. (If you do not know already how to do this, then ignore this solution.) Do so as follows.
export PATH="/Library/Frameworks/R.framework/Resources:$PATH"
To my understanding, this ensures that bash looks here for R (and anything else), then moves on to the other paths in PATH. Since this adds this path to the beginning of $PATH, an env variable, bash looks here first where it finds the newer version first, and stops looking.
When it comes to understanding PATH in the env set up in .bash_profile the following two links were helpful.
About PATH.
How to correctly add a path to PATH.
This solution may muck with anaconda's invocation of R. I have yet to check this.
First of all, you have to start terminal application. You can use either built in Terminal.app, or you can use replacement. My favorite one is iTerm2
https://www.iterm2.com
Then, you simply open terminal window and run R. Just like shown below:
Have fun with R!
Just ran into the same issue when installing R-4.0.3.pkg on my MacBook (MacOS BigSur). Can open R.app to the clunky R GUI, but typing in 'R' in terminal doesn't work.
Turns out, an R executable lives here: /Library/Frameworks/R.framework/Versions/4.0/Resources/bin/R
So I added this alias to my newly created .zshrc script:
alias R '/Library/Frameworks/R.framework/Versions/4.0/Resources/bin/R'
Now when I type in R, it opens... I swear this all happened seamlessly in earlier versions.
There is currently a bug in CRAN's R installation package that results in it not correctly installing symbolic links to R and Rscript for commandline use. I've just verified this by inspecting the postflight script in their 4.0.5 installation package. This only impacts MacOS system releases of 20 and above (you can check with uname -r).
I've included more info here, along with what the "correct" fix should be: manually creating symbolic links to /usr/local/bin that point to the R and Rscript binaries themselves. If this is the current challenge, then this would be a far better solution to creating aliases or manipulating PATH in various ways, since it's what the installation package intended to do (and presumably will again soon).
R: command not found
In short, if this is the problem, then Ashkan Mirzaee's answer (https://stackoverflow.com/a/67202173/2093929) to create the symbolic links directly is correct in form, but might not have the right link command. The 4.0.5 package intends instead to use:
mkdir -p /usr/local/bin
cd /usr/local/bin
rm -f R Rscript
ln -s /Library/Frameworks/R.framework/Resources/bin/R .
ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .
You can create a symbolic link from R and Rscript binaries to /usr/local/bin to add them to the PATH:
sudo ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/R /usr/local/bin
sudo ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/Rscript /usr/local/bin
Now which R should return /usr/local/bin/R and you can use R.
An easy way to open RStudio with admin privilege on macOS:
Go to Applications, then right click on RStudio
Select "Show Package Contents"
Go to Contents/MacOS
Now open terminal(in bash mode). Type sudo and drag the RStudio.exec into terminal and press on ENTER
Now RStudio will have admin access!

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.

Error using rscript

I have a Homebrew version of R installed on my Mac (OS X, El Capitan 10.11.5). I've been using rscript successfully for about two weeks now. However, when I tried to run a script this morning using rscript file.r, I get the following error:
/usr/local/Cellar/r/3.3.1/R.framework/Versions/3.3/Resources/bin/R: line 209: /usr/local/Library/ENV/4.3/sed: No such file or directory
/usr/local/Cellar/r/3.3.1/R.framework/Versions/3.3/Resources/bin/R: line 209: /usr/local/Library/ENV/4.3/sed: No such file or directory
Fatal error: cannot open file '': No such file or directory
(That is the full error. Yes, it appears twice, it is not a typo.)
After getting that error, I tried uninstalling and reinstalling r with homebrew. I get the same error. The only other package that I have installed since last using rscript (to the best of my knowledge) is pspp, but I see no reason why this should have affected rscript.
Of course, the error is saying that the file /usr/local/Library/ENF/4.3/sed cannot be found. Upon inspection of /usr/local/library this is, of course, true, but I don't know what the proper way to fix this is. It seems like rscript is just trying to access sed, which comes native on OS X.
Any ideas on what I can do?
This was found to be a bug contained within Homebrew/science. The error report can be found here: https://github.com/Homebrew/homebrew-science/issues/3839
Temporary fix for this (tested on OS X, as of 07-19-2016 12:54 PM central) from ck37 on github:
mkdir /usr/local/Library/ENV
ln -s /usr/local/Library/Homebrew/shims/super/ /usr/local/Library/ENV/4.3
Instead of doing the symlinks as a temporary fix, and until the r bottle is fixed. Short answer is to brew reinstall -s r.
I posted this answer (with an explanation to why this occurs) on the duplicate question which solved this problem for me.

Run JGR for R in Ubuntu 14.04 directly

I recently installed Ubuntu 14.04.2 LTS (trusty) and followed the instructions on http://r-interface.blogspot.nl/2012/04/install-r-jgr-and-deducer-in-ubuntu.html to install R, JGR and deducer.
If I run R, load JGR and open JGR from there, it works, but I like to create a shortcut directly to JGR. I tried simply locking the JGR console to the launcher, but if I then click on it, it will mention:
'Unable to start R: Unable to initialize R'.
In the above mentioned link, at step 4 I managed to create the desktop icon which should link to /usr/local/lib/R/site-library/JGR/scripts/run, but when I open that in the files browser, nothing happens. JGR also turns up empty when in the applications.
Anyone know how to do this?
I faced the same situation but it could be solved manually.
follow the same guide http://r-interface.blogspot.com.es/2012/04/install-r-jgr-and-deducer-in-ubuntu.html up to the point 4
in the point 4 , with R launched ( sudo R --no-save )
library(JGR)
JGR()
note that it prints in the screen the contents of a bash script. Something like (but use yours):
#!/bin/sh
export R_HOME="/usr/lib/R"
export R_ARCH=""
export R_LIBS="/home/jesus/R/x86_64-pc-linux-gnu-library/3.0:/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"
export R_LIBS_USER="~/R/x86_64-pc-linux-gnu-library/3.0"
export JAVA_LD_PATH="/usr/lib/R/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server:#JAVA_LD#"
'/usr/lib/jvm/java-7-oracle/jre/bin/java' -cp '/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/rJava/java/boot' -Drjava.class.path='/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/rJava/jri/JRI.jar:/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/iplots/java/iplots.jar:/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/JGR/java/JGR.jar:/usr/lib/R/etc/classes:/usr/lib/R/etc/classes/classes.jar' -Drjava.path='/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/rJava' -Dmain.class=org.rosuda.JGR.JGR -Djgr.load.pkgs=yes -Dr.arch= RJavaClassLoader
You only need to create the missing file /usr/local/lib/R/site-library/JGR/scripts/run (use the same name than in the guide, or adjust at your will) with the contents spat in the previous step.
Make it executable :
chmod a+x /usr/local/lib/R/site-library/JGR/scripts/run
Continue the guide where you leave the step 4

Resources