Cannot run R from terminal after upgrading to macOS Sierra - r

I recently updated my macbook to macOS Sierra (Version 10.12.3 (16D32)), and I am no longer able to run R directly from Terminal:
DN51ssqi:~ kjytay$ R
-bash: R: command not found
DN51ssqi:~ kjytay$ R --version
-bash: R: command not found
Opening R from the Applications folder or from RStudio works fine. Anyone experience this issue/has been able to fix it?
Here is my R version information:
platform x86_64-apple-darwin13.4.0
arch x86_64
os darwin13.4.0
system x86_64, darwin13.4.0
status
major 3
minor 3.2
year 2016
month 10
day 31
svn rev 71607
language R
version.string R version 3.3.2 (2016-10-31)
nickname Sincere Pumpkin Patch

This is just a guess, but I'm thinking this is probably an issue with your PATH settings, which might have been overwritten when you upgraded*. Seems worth a try at least. This is from the RStudio support pages**:
R from source (including MacPorts and Homebrew)
When R is installed from CRAN on OS X the R executable is installed at
/usr/bin/R. However, if R is installed directly from source or via a
package manager like MacPorts or Homebrew, then the R executable is
installed to either /usr/local/bin/R (Homebrew) or /opt/local/bin/R
(MacPorts). In order to support these variations, RStudio scans for
the R executable in the following sequence:
/usr/bin/R
/usr/local/bin/R
/opt/local/bin/R
If RStudio is not able to locate R by scanning these locations, it
will fall back to using whatever version of R is located at
/Library/Frameworks/R.framework/.
If RStudio is finding R OK, then you must have it at one of these locations. Make sure these locations are in your $PATH list:
In the Terminal:
echo $PATH
Will display your current PATHs list. If any of the locations in the RStudio quote are missing, you can see if that's where R is located by trying to specify that location. For example:
/usr/local/bin/R
If that works to start R, just add that location to your PATHs list:
export PATH=$PATH:/usr/local/bin
So that OSX knows where to find it!
* It's been noted elsewhere that homebrew breaks, for example, on upgrade to Sierra. Here's a blog post outlining some steps an R user might like to take after the upgrade: http://www.statsblogs.com/2017/01/26/upgrading-to-macos-sierra-nee-osx-for-r-users/
** Here's the support page where the quote is from https://support.rstudio.com/hc/en-us/articles/200486138-Using-Different-Versions-of-R

Related

How to view/change the installation of R that RStudio uses?

After installing either anaconda or jupyter, RStudio now shows some logs when installing packages, which indicate it's using R installed by anaconda, rather than the original version I had installed.
This is not a problem, until I try to install various packages, and I get some maze of frustrating c++ issues (due to graph dependencies).
What I've tried so far
Changed .libPaths() from the anaconda path to the default locations (but this doesn't help for R, only for R libraries)
Question
How can I tell which R installation RStudio is using, and how do I change it (from the anaconda version, back to the vanilla R version I previously had installed)
If you type version in the Rstudio console window it will tell you which version of R you are using...
> version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 6.3
year 2020
month 02
day 29
svn rev 77875
language R
version.string R version 3.6.3 (2020-02-29)
nickname Holding the Windsock
>
previous relaeases of R can be found here:
https://cran.r-project.org/bin/windows/base/old/
To those still searching for an answer and stumbled here
As listed above, basic info on the current R version is found entering this in the console of your RStudio
version
To view which R version is being used:
R.home() #tells you the R working directory
RSTUDIO_WHICH_R #tells you the source location of the R instance being used
Changing the version of R being used is much trickier. Consulting the official documentation can help, but realistically its easiest on Windows and a hassle on Mac/Linux. There might be some sneakier issues with Mac/Linux profiles and config variables, detailed more here
Best of luck!

Using a new windows version of R in Jupyter notebooks

I've installed R version 3.5.1 for windows and copied its contents to the R folder used by Anaconda3. However conda still identifies the current version as 3.4.3. Is there a "version id" file somewhere in the Anaconda3 folders?
Short solution
In short you need to install a the IRkernel package in the version of R you want to use with Jupyter and then make it available to Jupyter. See here.
Diagnosis
You may not be aware that you have two installations of R. To confirm this is the case in a Jupyter Notebook, type:
R.version
This should return values such as:
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 4.3
year 2017
month 11
day 30
svn rev 73796
language R
version.string R version 3.4.3 (2017-11-30)
nickname Kite-Eating Tree
Now open RStudio or RGui and input the same command, you should see different output (ignore any warnings):
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.0
year 2018
month 04
day 23
svn rev 74626
language R
version.string R version 3.5.0 (2018-04-23)
nickname Joy in Playing
Note the differences in the version.string and nickname variables in particular.
Now in your Jupyter notebook type:
R.home()
Which will give the output like:
"C:/Anaconda3/lib/R"
The same command in RStudio or RGui will return a different path e.g.:
"C:/R/R-35~1.0"
The above values may not match those on your machine, but if they are different to each other the following steps will allow you to use the latest R instance from Jupyter.
Longer solution
Copy the above R.home() path from Rstudio (or RGui)
Open Anaconda Prompt form the start menu
Type cd /d "C:/R/R-35~1.0" where the path is the same as the one you have copied. Hit return.
Type cd bin. Hit return
Type R.exe to launch the command line R from that directory
We now need to install the package IRkernel. This package makes the version of R callable as an Jupyter kernel. Type install.packages('IRkernel') and hit return.
Type IRkernel::installspec(name = 'ir35', displayname = 'R 3.5.0') to create the latest R kernel. Note you can change the name and display name to be whatever you wish.
Exit R and close any instances of Jupyter Notebooks you have running.
Launch Jupyter Notebook again and click to create a new notebook. You should find your kernel available by its display name in the drop down box.

R packages failed to install: x86_64-apple-darwin13.4.0-ar: No such file or directory - What is "ar"?

I go this error when installing R packages like RStan (and anything that depends on it such as brms) and Devtools. Since in the message displayed during the installation, everything before this look normal, I think the failure to install can be boiled down to this:
/Users/lambda/anaconda3/bin/x86_64-apple-darwin13.4.0-ar -rs ../lib/libStanHeaders.a cvodes/src/cvodes/cvodes.o cvodes/src/cvodes/cvodes_io.o cvodes/src/cvodes/cvodea.o cvodes/src/cvodes/cvodea_io.o cvodes/src/cvodes/cvodes_direct.o cvodes/src/cvodes/cvodes_band.o cvodes/src/cvodes/cvodes_dense.o cvodes/src/cvodes/cvodes_diag.o cvodes/src/cvodes/cvodes_spils.o cvodes/src/cvodes/cvodes_spbcgs.o cvodes/src/cvodes/cvodes_spgmr.o cvodes/src/cvodes/cvodes_sptfqmr.o cvodes/src/cvodes/cvodes_sparse.o cvodes/src/cvodes/cvodes_bandpre.o cvodes/src/cvodes/cvodes_bbdpre.o cvodes/src/sundials/sundials_band.o cvodes/src/sundials/sundials_direct.o cvodes/src/sundials/sundials_math.o cvodes/src/sundials/sundials_pcg.o cvodes/src/sundials/sundials_spbcgs.o cvodes/src/sundials/sundials_spgmr.o cvodes/src/sundials/sundials_dense.o cvodes/src/sundials/sundials_iterative.o cvodes/src/sundials/sundials_nvector.o cvodes/src/sundials/sundials_sparse.o cvodes/src/sundials/sundials_spfgmr.o cvodes/src/sundials/sundials_sptfqmr.o cvodes/src/nvec_ser/nvector_serial.o
make: /Users/lambda/anaconda3/bin/x86_64-apple-darwin13.4.0-ar: No such file or directory
make: *** [static] Error 1
ERROR: compilation failed for package ‘StanHeaders’
I got this same error both with Xcode compiler and clang4 compiler; I don't think the problem is with the compiler, but with the thing called ar. BTW, I have installed Rcpp and it works. I have seen others having the same problem when installing RPy2. So what is that ar thing and how to fix it?
R version:
> version
_
platform x86_64-apple-darwin13.4.0
arch x86_64
os darwin13.4.0
system x86_64, darwin13.4.0
status
major 3
minor 4.2
year 2017
month 09
day 28
svn rev 73368
language R
version.string R version 3.4.2 (2017-09-28)
nickname Short Summer
I just faced the same problem and I am using anaconda's Rstudio.
My way to fixed it is to install it in terminal, first to try these two on your terminal.
>conda install -c mittner r-rstan
>conda install -c r r-stanheaders #to install the packages in terminal
although I'm not sure where was wrong but it did work fine on me.
hope it helps.
// In the end it seems that there's something wrong with my Anaconda-Navigator, I reinstalled a RStudio and it goes fine.
I had the same problem with Rstudio from anaconda3. Then I from the anaconda navigator (Environments) I installed the gfortran_osx-64 package.
This got me the x86_64-apple-darwin15.5.0-gfortran binary under /anaconda3/bin.
Making a symbolic link did the trick:
elisa#~>ln -s /anaconda3/bin/x86_64-apple-darwin13.4.0-gfortran /anaconda3/bin/x86_64-apple-darwin1
I already solved this problem. I got this problem when using RStudio inside Anaconda. Later I installed R 3.4.3 and RStudio outside Anaconda and everything went smoothly. It might have been some problem with the Anaconda RStudio.

Multiple versions of R installed - terminal launching wrong / different R from RStudio

I am attempting to compile my R package, and realized that I have multiple versions of R installed on my mac, which is giving me difficulty. When I run 'which R' from terminal, I receive this:
Home$ which R
/Users/Home/anaconda2/bin/R
Home$ R
R version 3.2.2 (2015-08-14) -- "Fire Safety"
However, when I launch RStudio from my applications folder, and type 'version' in the console, I get this:
> version
_
platform x86_64-apple-darwin13.4.0
arch x86_64
os darwin13.4.0
system x86_64, darwin13.4.0
status
major 3
minor 3.2
year 2016
month 10
day 31
svn rev 71607
language R
version.string R version 3.3.2 (2016-10-31)
nickname Sincere Pumpkin Patch
So I have 3.3.2 on RStudio (the version I want for compiling my package), and 3.2.2 from anaconda being launched in terminal when I type R in terminal.
How can I fix this? Do I have to change my path to find the correct version of R when I launch from terminal? How do I find the correct path?
Thanks!
I bet anaconda has just inserted its path at the front of your PATH variable and is overriding your newer 3.3.2 version at the terminal. If you want your 'RStudio' version to be the default version that pops up at your terminal when you type 'R', then you gotta modify your PATH. No biggie.
First, figure out which R version RStudio points to. Type the following into your RStudio console:
Sys.which("R")
I bet you'll see something like /usr/local/bin/R. So that's what you have to add to the front of your PATH (minus the '/R').
To confirm that anaconda has messed you up, open up your terminal and check out your PATH:
echo $PATH
You'll probably see /Users/YOURNAME/anaconda2/bin as the first entry in your PATH, and further down you'll see /usr/local/bin. We have to flip this order. There are a million ways to fix this. Here's the quick and dirty solution -- add the following to the bottom of your .bash_profile
export PATH="/usr/local/bin:$PATH"
And type R --version in your terminal to confirm that your default R has changed.
You might get fancy later with sed or awk if having two /usr/local/bin entries in your PATH annoys you (as it would me).
First go to the directory /Library/Frameworks/R.framework/Versions
Here you should see various versions of R that you have installed.
To change to say version 3.4 use the following sequence of commands in the Terminal:
cd /Library/Frameworks/R.framework/Versions
unlink Current
ln -s 3.4 Current
I highly recommend RSwitch. It's a tiny program that allows you to select from any installed R version, press one button, restart your R session and you'll be using the selected R version.

RStudio can not use git in Yosemite

After upgrading my Mac to Yosemite, I am not able to use git in RStudio anymore.
(I can still use source tree or git independently from RStudio)
Not sure whether it is related to the PATH issue posted here:
Running system command from R console cannot locate installed programs since upgrading to Mac OSX 10.10
I tried the above solution, but did not work.
In RStudio, I specified the path to Git in Tools/Global Options.../"Git/SVN" correctly (as I used before)
But, in in Tools/Project Options.../"Git/SVN":Version control system the only option left is (None).
RStudio: 0.98.1074 (updated to 0.98.1083, still does not work)
version
_
platform x86_64-apple-darwin10.8.0
arch x86_64
os darwin10.8.0
system x86_64, darwin10.8.0
status
major 3
minor 1.0
year 2014
month 04
day 10
svn rev 65387
language R
version.string R version 3.1.0 (2014-04-10)
nickname Spring Dance
I encountered the same problem. When you enter the directory you used to use with git in your terminal (cd path/to/directory) type git status. In my case I received the message:
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
Apparently, I had to agree to the Xcode licence. When you re-run the line with sudo (sudo git status) and enter your password in the terminal you get the whole license displayed. Now you only need to type agree and everything is done. Re-start RStudio and the git functionality is back again.
Best wishes,
Marco

Resources