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

Installing R for Ruby Data Science using Homebrew

How to install R environment for statistical computing using Homebrew.

Step 1 - XCode Command line

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

xcode-select --install

Step 2 - Install Homebrew

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

Step 3 - xQuartz

You need to install xQuartz using Homebrew Cask extension.

brew install cask

Install xQuartz

brew install caskroom/cask/xquartz

Step 4 - R

Finally, we can install R!

brew install r

Step 5 - 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 6 - Double Check Your Work

Running Doctor will ensure your system is stil healthy

brew cask doctor

Cleanup any files.

brew cask cleanup

Step 7 - 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)

Troubleshooting

If homebrew ends up changing stuff and you can no longer find the right package, try brew search.

brew search <name of package>

Source


Resources