Chris Mendez in For Developers, Tools for Software Engineers, Data Science, Homebrew

Installing R for Ruby using Homebrew

Here's how to install R using Homebrew.

Step 1 - XCode Command line

If you're on a Mac, you will need to install XCode command-line tools.

xcode-select --install  

Step 2 - Homebrew

Homebrew is a package manager for Mac and if you haven't installed it yet, follow this tutorial.

Step 3 - Science Formulæ

We will need to install the scientific formulae using Homebrew Science.

brew tap homebrew/science  

Step 4 - xQuartz

You need to install xQuartz using Homebrew Cask extension.

brew install cask  

Install xQuartz

brew install caskroom/cask/xquartz  

Step 5 - R

Finally, we can install R!

brew install r  

Step 6 - TK Graphic Library

Let's be safe and install Homebrew Dupes which will allow you to have a duplicate on homebrew.

brew tap homebrew/dupes  

Install the TK Graphical Library.

brew cask install tcl  

Step 7 - Double Check Your Work

Running Doctor will ensure your system is stil healthy

brew cask doctor  

Cleanup any files.

brew cask cleanup  

Step 8 - Run R

If everything is working properly, you should be able to run R (notice that it's capital) and the TK GUI. This GUI is what you will be using to visualize your statistical questions.

R -g Tk &  

Bonus - ggplot2

R uses a package manager to help organize open source libraries. The most popular library is Comprehensive R Archive Network and within in, is a graphic package called ggplot2.

ggplot2 is a graphic package based on the idea of composing plots using multiple layers that can be stacked on top of each other. Think, Photoshop for big data. There are many other graphic packages such as qplot (quick plot) but it's just easier to learn ggplot2 once and for all.

Check for R

which r  

Start R

r  

Install ggplot2 through CRAN

install.packages("ggplot2")  

Load ggplot2 into your R application

library(ggplot2)  

Resources