Home » Uncategorized

Foolproof R package Install

The number of R packages associated cool new tricks available continues to grow every month.  To understand the current state of R packages on CRAN, I ran some code provided by Gergely Daróczi on Github .  As of today there have been almost 14,000 R packages published on CRAN and the rate of publishing appears to be growing at an almost exponential trend.Additionally, there are even more packages available on sources like Github, Bioconductor, Bitbucket and more.   

Foolproof R package Install

Approaching package issues systematically

Given the amount of tools the average data person uses daily, we need to reduce the hurdles to as many “easy tasks” as possible.  To help other poor souls that don’t want to think too hard when struggling to install R packages referenced in tutorials or other media, I’ve put together a simple flow chart.  The basic troubleshooting guide can be followed in the flow chart. However additional detailed instructions and links can be found below the image. 

Foolproof R package Install

Additional instructions for Package Install troubleshooting flow chart

Is the package available on CRAN? 

  • Unfortunately CRAN does not have a search but you can usually find the package by googling  “CRAN R <package name>”

Do you have the right version of base R? 

  • To identify your R version, execute the command “Version” and the output will indicate your installed base R version.  In the screenshot, I have version 3.4.3
  • To install a new version of R, visit their download page

Foolproof R package Install

Did the install work?

  • If the install worked, you will get a message along the lines of “The downloaded binary packages are in <filepath> “

Install via R-Studio package interface

  • This is a very handy tip which prevents silly typos.  The tip was given by Albert Kim in reply to my #rstats tweet.  He documents this in his awesome book: Modern Dive An Introduction to Statistical and Data Sciences via R.  

Foolproof R package Install

Locate the package repo and install via devtools

  • Typically the easiest way to locate the package repo is by googling “r package <package name>”.  In the case of the emo R package I found it here: https://github.com/hadley/emo
  • Install the package from the repo via devtools.  This simply involves installing and loading the devtools package and then executing the appropriate “install_” command from the docs.  In the case of the emo package, the following code will work.
install.packages("devtools") 
library(devtools)
install_github("hadley/emo")

# OR MAC and Linux users can simply do: 
devtools::install_github("hadley/emo")

Thank you

Thank you for taking the time to read this guide.  I certainly hope that it will help people spend less time thinking about package install debugging and leave more time for fun data analysis and exploration.  Please feel free to let me know your thoughts in the comments or on twitter.  Thanks!

Original Post can be found here.

Leave a Reply

Your email address will not be published. Required fields are marked *