19

I use a MacBook Pro 13" Retina (Late 2013) with OS X Yosemite 10.10.2. I wouldn't wish this upon my worst enemy. Well maybe.

Nightmare in chronological order:

  1. Downloaded R and RStudio from official sites.
  2. Ran both apps a few times, fine.
  3. Installed Homebrew. Ran "brew doctor" in Terminal. Brew doctor said the R files were problematic.
  4. RStudio started acting weird.
  5. Downloaded ggplot2 R package via CRAN mirror. 5GB of data clogged the "private/var" file. Deleted some data in there.
  6. Mac freaked out. Kernel panic until an Apple Store Genius erased the Mac and reinstalled OS X.

I want to continue using R and RStudio. Questions:

  1. How do I go about this without blowing up the Mac again?
  2. How to install R and RStudio via Homebrew?
  3. Do I need to install XQuartz first?
  4. What would happen if I install R and RStudio unbrewed?
  5. What conflicts between R, RStudio and Homebrew should I recognize?
  6. Common quirks of having all of Homebrew, R, and RStudio installed?
  7. How can I make Homebrew, R, and RStudio live happily ever after without burning down the house?

Thanks!

Elan
  • 539
  • 1
  • 6
  • 18
  • You probably had two installations of R at one point. The "official" version and a second brew-version. The maintainer of the Mac fork of R suggests not using any of fink, Macports, or homebrew because their default locations for programs are different than what are assumed in the stock version of R that is distributed in binary form. There are people who are using brew, but they know more than me or you about how the inter-dependencies are managed in Unix. – IRTFM Mar 12 '15 at 18:24
  • Why get the official R for OS X from CRAN, get an official Rstudio and then also homebrew? You're better off with either official stuff or exclusively homebrew generated stuff. In the latter case you're on your own. You can get all required compilers from Apple and fortran from [http://r.research.att.com/libs/](http://r.research.att.com/libs/) if you need to compile when building an R package because those were used to generate R. All "stuff' from CRAN and any additional tools required have always worked for from OS X 10.6.x upto OS X Yosemite. – Bhas Mar 12 '15 at 18:39
  • I have 3 OS X systems. All 10.10.2. All using latest RStudio (Preview), R 3.1.2 (official CRAN binary) and up-to-date homebrew. No issues whatsoever. – hrbrmstr Mar 12 '15 at 19:18
  • R is a complete nightmare, I am totally shocked that this is even close to rivaling Python... it takes monumental effort to get working, complete garbage. – Shaun Stoltz Aug 17 '19 at 10:50

2 Answers2

36

How do I go about this without blowing up the Mac again?

Don't try to delete your swap file while the computer is running! If you start deleting random system files you're going to have a bad day.

How to install R and RStudio via Homebrew?

You can install R with brew install r. You can install a binary RStudio using homebrew-cask, like brew install Caskroom/cask/rstudio.

Do I need to install XQuartz first?

No, this should no longer be necessary.

What would happen if I install R and RStudio unbrewed?

Nothing bad; brew doctor may report findings but these are not errors and you should not assume they represent problems, though they are helpful to maintainers like me if you seek help trying to diagnose build failures later.

What conflicts between R, RStudio and Homebrew should I recognize?

There are no important conflicts. If you install the compilers from http://r.research.att.com/libs/, which are unnecessary if you're using a brewed R, you may later have trouble installing things like gcc (which provides gfortran) from Homebrew.

Common quirks of having all of Homebrew, R, and RStudio installed?

As of August 2015 the comments below are no longer necessary; packages are now installed to /usr/local/lib/R/x.y/site-library by default and should survive minor R upgrades.

If you are using a brewed R and you would like your installed packages to survive minor R upgrades, you can run mkdir -p ~/Library/R/3.2/library and then R will install packages to that path by default (placing the packages in your home directory and not in the Cellar).

How can I make Homebrew, R, and RStudio live happily ever after without burning down the house?

See above!

shekeine
  • 1,445
  • 10
  • 22
Tim Smith
  • 6,127
  • 1
  • 26
  • 32
  • Thanks Tim, great tips! Installed R and RStudio via Homebrew. – Elan Mar 14 '15 at 16:40
  • @TimSmith, given all packages now go to `/usr/local/lib/R/x.y/site-library`, what happens to them and what do I need to do when `R` upgrades to higher major version (e.g. from `x.y` to `x.z`)? Is it recommended or better to specify a common path to which a brewed `R` install packages regardless the version `x.y` so that later version of a brewed `R` can continue using the packages? – skyork Sep 26 '15 at 01:05
  • Since R has a concept of versioned package directories I assume that R does not promise that packages with compiled C code are binary-compatible across minor release versions, so I believe that using an unversioned package directory may lead to crashes after R upgrades. (This is the case for e.g. Python.) I'm not completely confident about this, though; if you can find any documentation about the promises R makes about package compatibility over upgrades, I'd be interested! – Tim Smith Sep 26 '15 at 17:03
0

Looking back at this issue, considering all the helpful comments and answers, regarding downloading R packages on a Mac with R and Homebrew already installed:

Do it in the R console within the RStudio interface, simply by typing install.packages("name of the package")

Since I had started downloading R packages directly in RStudio, I hadn't had any problems. The system is very happy.

Elan
  • 539
  • 1
  • 6
  • 18
  • I'm having problems while installing multiple packages (for example, tm).. this is what is get ```------------------------- ANTICONF ERROR --------------------------- Configuration failed because libxml-2.0 was not found. Try installing: * deb: libxml2-dev (Debian, Ubuntu, etc) * rpm: libxml2-devel (Fedora, CentOS, RHEL) * csw: libxml2_dev (Solaris) If libxml-2.0 is already installed, check that 'pkg-config' is in your PATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-config is unavailable you can set INCLUDE_DIR and LIB_DIR manually via: R CMD INSTALL --configur``` – nyxee May 29 '18 at 00:27
  • @nyxee see if the answer to this question helps; it suggests manually installing `libxml2` https://stackoverflow.com/questions/31797524/r-devtools-fails-as-package-libxml-2-0-was-not-found-in-the-pkg-config-search-p – Elan May 29 '18 at 03:35