Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
One of the reasons why I love R is that I feel like I’m constantly finding out about cool new packages through an ever-growing community of users and teachers.
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.
Last week, I was heading out on a trip. I excitedly planned my air time to do some fun new R tutorials. The night before the flight I attempted to install all required packages or files so that I wasn’t struggling with slow plane wifi. Unfortunately the following packages kept giving me install issues: quanteda, magrittr and emo. As per usual, I executed the install.packages() command to install the packages.
install.packages("magittr") install.packages("emo") install.packages("quanteda")
I recieved the following sad warnings:
Warning in install.packages : package ‘magittr’ is not available (for R version 3.3.3) Warning in install.packages : package ‘emo’ is not available (for R version 3.3.3) Warning in install.packages : package ‘quanteda’ is not available (for R version 3.3.3)
R- why are you making me think?
Why? Why is my loving R betraying me and making me overthink the install of some packages? It’s 11 at night before my early AM flight. I really do NOT want to be reading through stack overflow for package install troubleshooting help at the moment. Adding insult to injury, the warning messages are not super helpful.
I know it’s lazy, but given how many tools us data people use every day I feel like we shouldn’t have to think very hard about installing packages. We should be thinking about the data and analysis.
A Cry for help
So I haphazardedly try a bunch of stuff, nothing works and I have a lightbulb moment! The lovely women at R-Ladies Austin were just telling me that if I ask a help question on twitter with the #rstats tag someone may take pity on me and answer. Having nothing to loose I give it a shot and luckily as I slept the help piled in!
So what did I do wrong? Well umm.. what didn’t I do wrong? I had the wrong version of R for one package, I made a typo on another and I was trying to install a package from CRAN that was on github only. This all seems pretty silly, but how would I guess these mistakes from the error messages above? And the more important question is how can I pay forward the help I got to prevent others from making the same mistakes?
Approaching package issues systematically
To help other poor souls that don’t want to think too hard when struggling to install 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.
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 the download page
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.
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!
Written by Laura Ellis
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.