Skip navigation

NOTE: The comments are a must read for this. Some excellent additional advice and “gotchas” by some super-helpful readers.


I was in a conversation with an academic colleague (wicked smart dude) and the subject of installing R came up (NOTE: this will happen to you, too, if you ever have the misfortune to have a face-to-face convo with me ;-). They noted that getting up and running with R was not as seamless as one would like it to be and, to be honest, I have to agree, especially after typing the rest of this post out.

I recently had a similar experience helping folks who use Windows get R & RStudio up and running and that’s even more of a nightmare, especially if you do not have Administrator privileges (or, perhaps I just scare easily).

Prior to these experiences, I never really stopped to consider just how less friendly the installation process of R is when compared to Excel, Tableau or other apps one might use for data analysis and visualization. Hopefully this will becomre a top priority for the R Consortium.

Since this colleague uses OS X, I offered to put together instructions for how to get R & RStudio installed and finally had 5 minutes to crank out a blog post to help the broader community with the information.


Get R

R_for_Mac_OS_X


Verify R itself is working

  • Look in the Applications folder for the R application.
  • Double-click it and you should see an R console window.
  • If that did not work, try installing R again
  • Once you’ve verified R is working, quit the app

R_Console


Download RStudio

RStudio is an integrated development environment for R that will make your life and coding easier.

RStudio_-_Download_RStudio


Verify RStudio & R are working together

  • Look in the Applications folder for the RStudio application.
  • Double-click it and you should see an RStudio window with four panes.

niasra_uow_edu_au_content_groups_public__web__inf__math_documents_mm_uow183084_pdf

From now on, just start RStudio when you want to work in R.


[Optional] Install XQuartz

Some functions in R require an “X11 Server” and/or libraries associated with an X11 server. Apple does not provide this software with OS X anymore so you have to do it on your own via a third-party application called XQuartz.

XQuartz


[Optional] Install Xcode Tools

Some R packages require compilation. That requires utilities not installed on OS X by default. You can wait to do the following until it’s needed, but since you’re already installing things…

  • Get Xcode https://itunes.apple.com/us/app/xcode/id497799835?mt=12 and install it like any “normal” Mac application
  • When the intallation is done, open Xcode then close it just to verify it installed correctly
  • Find and open the Terminal program in the Utilities folder under the Applications folder
  • Paste the following into the Termainal window and hit enter/return (accept any dialog/prompt):
xcode-select --install`
  • Close the Terminal application

[Optional] Set yourself up for easier future compiled package installation

Some R packages need additional libraries to work and most aren’t on your system by default. There are a myriad of ways to get these libraries, and the way I obtain them is via the homebrew utility. You can save yourself the trouble of installing homebrew later by doing the following now:

  • Find and open the Terminal program in the Utilities folder under the Applications folder
  • Paste the following into the Terminal window and hit enter/return:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Read and accept the various prompts until it’s installed
  • Close the Terminal application

You can now do brew install xyz in the future when a library is needed to support a package. Drop a note in the comments if you’d like this discussed more in a future blog post.


[Optional] [If you have an hour+ to kill] Install MacTeX

R has an academic history and there are many semi-advanced functions that are tied to something called latex. Installing latex for OS X is not hard, just time (and bandwidth) consuming (it’s about the same size as a new OS X installer). If you delve into package creation or do more detailed output work in R, you’ll want to install MacTex sooner than later.


Fin

If you have any changes/additions/etc drop a note in the comments. I may even stick this on github to make it easier to contribute in the future.

13 Comments

  1. Much easier with homebrew, and also easier to keep up to date:

    “`

    R

    brew tap homebrew/science
    brew install R

    Rstudio

    brew tap caskroom/cask
    brew install rstudio
    “`

    • Totally agree, but the main reason I didn’t include the bit for “R” proper is that anyone seeking “official” help on the R mailing lists (and sometimes even on SO) will get berated by the “old guaRd”. I think I do need to turn this into a mini-wiki or open source ebook since keeping up to date with RStudio (dailies) is so easy this way.

    • ARGH. Yes! I totally forgot to overtly state that and I’ve been bit before on new installs on OS X when I forget to ensure it’s available (my linux installs are scripted and include this). I’ll update the post later today. Huge #ty for the reminder.

      • Great post! I’ve been thinking of typing something like this up, even for my own benefit, as the little bits of install notes I leave lying around never seem to make a complete picture when I try and help someone else get their machine to be able to build packages as mine can.

        Lately I’ve found the gfortran step one of the hardest. In particular, the package that is (kindly) provided at:

        https://cran.r-project.org/bin/macosx/tools/

        will not work for the “Mavericks” version of R, which requires gfortran-4.8.2.

        There is a “mystery” page that I’ve found (but don’t know if anything specifically links to it) that provides a binary for gfortran-4.8:

        http://r.research.att.com/libs/

        However, there seems to be some inconsistency based on particular architectures. For “older” machines, that binary is too new, and won’t work in Mavericks-R. For some machines (late early 2009 Macbook Aluminum) I found that installing gfortran-4.8.2 from:

        https://gcc.gnu.org/wiki/GFortranBinaries#MacOS

        worked, but for another (late 2008 Macbook aluminum) it didn’t work. In that case, I ended up having to go with homebrew R, since it was the only way to get the R binaries and gfortran compilers consistent.

  2. For command line and package manager addicts like me, there is also the possibility to install R via homebrew or macports. It makes keeping R up to date easier IMO.

    • Totally agree, but the main reason I didn’t include that is that anyone seeking “official” help on the R mailing lists (and sometimes even on SO) will get berated by the “old guaRd”. I think I do need to turn this into a mini-wiki or open source ebook.

      • The R community is now used to online books like Hadley Wickham’s excellent ones, so you could set up something like that on github. Though I imagine people will start finding this page, regardless.

  3. Just to clarify about XCode installation, you wrote:
    * When the intallation is done, open Xcode then close it just to verify it installed correctly
    * Find and open the Terminal program in the Utilities folder under the Applications folder
    * Paste the following into the Termainal window and hit enter/return (accept any dialog/prompt):
    xcode-select –install`

    1) It looks like the command in Terminal is supposed to perform the installation; yes? Or, if we’ve already double-clicked the icon in the Applications folder and used the GUI installer, is there an additional step?
    2) If there’s no additional step, maybe the first bullet I quoted above was supposed to say “download” instead of “installation”? It did take quite a while for the program to be available to click on.
    3) The Terminal command seems to include a single trailing backtick, which seems like a typo. Is it an extra character, or is there another option that was supposed to be enclosed in backticks but got cut off?

  4. Hi, thanks for this post. It is really useful!

    I am working in a MacBook Pro (15 inches, mid 2010), OSX El Capitan (10.11.6), 2.4 GHz Intel Core i5, 8 GB 1067 MHz DDR3

    Today (June 13, 2017) I tried to update from R-3.3 to R-3.4.0. I downloaded the R-3.4.0.pkg from https://cran.r-project.org/ site. After downloading I checked the MD5 checksum for the R-3.4.0.pkg image and it was the same than in the r-project website. I executed the file by double-clicking and everything appear to work fine, at the end it said that everything was installed with no problem.

    The problem I have is that the old R.app was removed from my application folder but the new (R-3.4.0) does not appear in the application folder either.

    I tried to download and install the GNU Fortran 6.1 and then reinstall R but nothing changed.

    I tried to look for a solution in google and this forum but did not find any clue of what to do. I hope I am not missing any stupid detail or making a rookie mistake.

    Thanks for your help

  5. The links to R 3.3.2 do not work, where can I get this, it seems like I can not find it anywhere in the web …

  6. Hello,

    I’m a couple of years late to the party but still this is a very useful post that I found slightly too late after I’ve done it myself haha.
    Either way, I am wondering if there’s a way that I can have the things I need in R that I get from installing Xcode, without having to install all of Xcode. (16 GB)
    I made the mistake to buy a small SSD storage in my mac and it’s haunting me now. I want to save space by removing Xcode.
    Can I still use most of R if I only install the command line tools? Some posts on the internet make me believe that that’s enough.
    Any help is appreciated as I’m still very much a beginner with the coding and R.
    I’m running Mojave 10.14.6

    TL;DR: R is working fine with everything installed now, I’m just trying to save space without breaking R. (By removing Xcode and installing Command Line Tools only?

    Thanks! -JK


2 Trackbacks/Pingbacks

  1. By Installing R on OS X | rud.is on 22 Oct 2015 at 7:35 am

    […] The comments are a must read for this. Some excellent additional advice and “gotchas” by some […]

  2. […] a previous post I provided “mouse-heavy” instructions for getting R running on your Mac. A few of the […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.