Where to start with R?

  • Open source
  • Sharable
  • Huge community
  • Real programming langage (not the case of SAS or Stata)
  • Strong ecosystem
  • Increasingly used, especially among data scientists

RStudio is the best possible tool to work with R. It's an IDE that is available on Windows, Mac and Linux.

On top of RStudio, you will also have to install R itself.

The easy way to install R on macOS is to download the installer. But… updating R with this method is quite painful, as there is no automated way of doing it. In other words, to update R, you will have to manually check the installer page, and download the new installer if there is a new version out there.

An easiest way to install and update R is through Homebrew.

Note that this method does not install the little R app, but if you use RStudio (and I recommand you to use it), you don't need this little app1).

Install Homebrew

Homebrew is a package manager for macOS. It is used in the Terminal, and it is a very powerful way of installing various softwares.

If you do not have Homebrew installed on your machine, open the Terminal app and paste this (as of December 16, 2018):

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

If it's not working, please visit this page.

If you're not sure if Homebrew is installed or not on your machine, type brew -v in the Terminal. If you receive an error message, then you will probably need to install Homebrew.

Once Homebrew (or brew) is installed, to install a new package or application, you just need to type brew install <APP>, where <APP> is replaced by the app you want to install.

Note: for an application to be installed via brew, it has to be in the brew repositories. The main list is here, and for desktop apps you can also have a look at Cask.

Install R via Homebrew

Before installing R via brew, you should install the Apple's XCode Command Line Tools (CLT). You can install R without it, but it will take way more time without it (as brew will compile GCC, whereas CLT provides an already compiled GCC).

xcode-select --install

This command will fire a window asking you to install CLT. It is perfectly normal.

And then, the installation itself:

brew install r

If you type r in your Terminal, you will now see the R interpreter. To close it, type quit() and answer n when asked if you want to save workspace image.

R is now installed on your machine!

Update R via Homebrew

R is now installed as a brew package. To update R, you just need to tell brew to update all of the installed packages.

brew update
brew upgrade

brew update tells brew to update all its metadata. This way you are sure brew will download the latest versions of all your installed packages.

brew upgrade takes care of the updating. Beware that this command will update ALL your installed packages!

Just run this double command regularly (once a month for instance) to automatically update R. As you can see, it is way easier to update R with this than going to the webpage, downloading the installer, installing the new version manually, etc.

And if there is no new version of R, brew will just tell you that your system is up to date. It's that simple!

Reinstall R

If you have any trouble with your R installation, brew provides a simple way to reinstall it:

brew reinstall r

Transition from the installer to Homebrew

Maybe you first installed R via the installer, and now you want to use brew.

To avoid any conflict between the two versions, I would advise you to first uninstall R (see below) and then to install it via brew.

If you already installed R via brew while not uninstalling the installer version, no worries! Just uninstall the installer version, and reinstall the brew version with brew reinstall r.

Uninstall R

If you have installed R via Homebrew

brew uninstall r

That's it!

If you have installed R via the installer


1)
If you absolutely want to install it, you can download it here. It's the Mac-GUI stuff.
Enter your comment. Wiki syntax is allowed:
If you can't read the letters on the image, download this .wav file to get them read to you.
 
  • Last modified: 4 months ago
  • by Olivier Simard-Casanova