2
votes

I am struggling with how to link/sync the version of R that I access from the bash terminal on Mac OSX to the version of R (and R libraries) that I have in R Studio.

Some background:

I installed R/R studio by downloading the most recent versions available from the developer's websites as of 10/9/2016.

I previously had R installed on bash, but that version was 3.2.5 not 3.3.1 that I downloaded online. So if I tried to open an R script from bash, it would launch a deprecated version of RStudio that crashed.

To fix this, I used Brew to unlink the old version of R, and reinstall R in bash. brew unlink r brew install R

The Problems:

Now when I launch an R script from terminal, it opens the correct version of RStudio, which has a version:

version.string R version 3.3.1 (2016-06-21) nickname Bug in Your Hair

However, if in bash I simply launch R using $ R, I have version:

R version 3.3.0 (2016-05-03) -- "Supposedly Educational"

Furthermore, the packages installed in RStudio are not linked. In Rstudio I can load a package library such as library(tidyverse) without error.

In bash's $ R, the above command library(tidyverse) throws an error:

Error in library(tidyverse) : there is no package called ‘tidyverse’

What I would like is a way to link the bash version of R and Rstudio such that the R-versions are the same and such that packages installed in R are recognized in RStudio, and RStudio installed packages can load in bash R.

Thanks for your help.

1

1 Answers

0
votes

The default behavior should be that R and Rstudio share the same versions and packages. I imagine the issue you're seeing has to do with having an outdated version of homebrew at the time of install.

I would recommend uninstalling and re-installing, as I was unable to reproduce your issue using the latest Homebrew packages:

brew uninstall r
brew update
brew update # (run twice)
brew cleanup
brew doctor

Fix any issues raised by brew doctor

brew tap homebrew/science
brew install r

I did not have Rstudio installed, so I installed it from Homebrew using cask -- This should not be necessary if you already have Rstudio installed from the developer's site.

brew cask install rstudio

After taking these steps I get the following in both R Studio and in the terminal:

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
library(tidyverse)
Error in library(tidyverse) : there is no package called ‘tidyverse’

At this point, in my terminal window, I ran:

install.packages("tidyverse")

Finally, returning to R Studio after the install:

> library(tidyverse)
Loading tidyverse: ggplot2
Loading tidyverse: tibble
Loading tidyverse: tidyr
Loading tidyverse: readr
Loading tidyverse: purrr
Loading tidyverse: dplyr
Conflicts with tidy packages --------------------
filter(): dplyr, stats
lag():    dplyr, stats