In an organization with say, more than 10 people, letting users manage their own installations has goat rodeo written all over it. For this reason, I’m guessing your responsibility for software installations is inversely proportional to the size and sophistication of the organization you work for.
So, if you’re an occasional user of R at home or perhaps the lone statistician in your small office with limited tech support, this post’s for you. One of the things I like about R and other open source software, in addition to accessibility, is the fact that it they are constantly evolving. Similar to Stata and SAS, R has a modular structure. When you download a version of R, it comes with a set of built-in functionalities. Once you’ve installed a version, you can then enhance your installation by choosing from the vast selection of packages contributed by other R users, kind of like a smorgasbord with a lot more quality control.
If you’re like me and not a daily R user, you notice you need an upgrade when you unpack your latest find from R-CRAN and it refuses to load or otherwise play nicely with your base installation. Luckily, your new package should give you a warning message with the version your package was built in.
These instructions are for those of us using computers running the 32-bit version of Windows 7.
Installing R the first time (difficulty level = easy)
Over time, you will likely become a frequent visitor to CRAN, which stands for Comprehensive R Archive Network.
- Comprehensive: CRAN houses all of your R base versions and tested packages.
- Archive: CRAN keeps a historical cache of all previous versions, with documentation.
- Network: R downloadables are distributed or “mirrored” on many servers around the world (16 currently in the U.S.), each with identical versions of the base software and packages. For a faster download, you will be encouraged to choose a mirror geographically closest to you.
Adding Packages (difficulty level = easy)
The R Base Package contains its “basic” functions, which include the standard arithmetic, statistical, and processing tools and some useful, not-as-basic (e.g., “Fuzzy” string matching) functions.
All contributed packages are linked with short descriptions here. It’s easy to be tempted by greed. At the time of this writing, there were 5019 available packages contributed by talented and generous folks to share. Rob Kabacoff has provided a gentle introduction to R packages on his site, Quick-R.
I find examples helpful, so here’s mine. To analyze survey data, you need special tools to calculate the variance in a way that reflects the sampling design. Josh Pasek’s “Weights” package allows for calculation of weighted frequencies, means, and other statistics with variance estimates that take the design into account.
- Reminder: Before you can run a package, you need to know, download, and unpack other packages your target package depends on. You will need call them first in your library statement(s). Dependent packages will be linked next to the package itself on the CRAN site and should download with the package you’re looking for. To keep my directory neat, I have my packages saved in one folder with the admittedly unimaginative name, ‘packages’.
Here’s an example of the installation command, which will unpack your new module. After invoking the command, the R base software will walk you through the next steps.
- Reminder: R developers are a sharp group, but I’m pretty sure they’re not clairvoyant. So, if you choose to store your packages in a non-standard location (e.g., C:/Program Files/R/R-3.0.2/library/) , be mindful that calls to other functions (e.g., install_github()) may need help finding them. Adding your own “package” directory path to the front of the .libPaths variable (e.g., .libPaths( “c:/R/packages” ) ) could prevent hours of head scratching. <-- spoken from (embarassingly) personal experience.
As I mentioned at the beginning, R is constantly evolving. It is possible to have two separate versions of R running on your machine. Luckily, Christopher Gandrud is and has written detailed instructions on the management and citing of various R package versions. The good news is also that installing R is incredibly easy and, as mentioned before, CRAN keeps all of the old versions in an archive. So, uninstalling your current version of R and replacing it with a newer one seems like a pretty low risk approach, especially if you are a beginning R user.
- Uninstalling R can be done from your Windows control panel. You uninstall R just like you uninstall any other program. Scroll down to find the R version (e.g., the Trick or Treat” version, R for Windows 2.15.2) and simply hit ‘Uninstall’. Reinstalling is now just a matter of going to the CRAN site, finding the most recent version, and downloading from a mirror near you.