Skip to content

Instantly share code, notes, and snippets.

@johnrc
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnrc/c0511755e8493d2b0ad9 to your computer and use it in GitHub Desktop.
Save johnrc/c0511755e8493d2b0ad9 to your computer and use it in GitHub Desktop.
Useful commands for R

Installing packages

Install package and dependencies to a specific location. If you want the binaries cached, use destdir="/Rbins" option. If you want the package(s) installed to a specific location, use lib="~/Rlibs". The default location on Windows is %userprofile%\Documents\R\win-library\3.0.

install.packages("<package>", dependencies=NA, repos="http://cran.us.r-project.org")
R CMD INSTALL <package> -l ~/Rlibs

On Mac it would be something like

install.packages("<package>", dependencies=NA, type="mac.binary")

**If you don't use type then it'll fall back to compiling and installing from source. This may happen anyway since not all packages are compiled for Mac.

Locations where libraries are pulled from:

.libPaths()

Add an entry to .libPaths()

.libPaths(c(.libPaths(), "/Rlibs"))

Load the library

library("<package>")
library("<package>", lib.loc="~/Rlibs")

Upgrade packages by following the steps in this SO answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment