Download presentation
Presentation is loading. Please wait.
1
R Package Management By Toni Lee McCreash
2
What, exactly is an R package?
Packages are collections of R functions, data, and compiled code in a well-defined format. Two or more functions together Based on a single topic or theme (e.g., biology, physics, finance, etc.) Documentation regarding the package The directory where packages are stored is called the library. R comes with a standard set of packages. Others are available for download and installation. Once installed, they have to be loaded into the session to be used. Source:
3
What are the components of a package?
content/uploads/2015/06/devtools-cheatsheet.pdf
4
Finding Your Library Folder(s) There are 2!
System Folder C:\Program Files\R\R.3.2.2\library Local Folder C:\Users\user.name\Docume nts\R\win-library\3.2
5
Viewing Installed Packages in RStudio
6
How are packages managed?
What packages do I already have? installed.packages() Source:
7
installed.packages() installed.packages() installed.packages()[1,]
8
Check if installed? Did I already install a specific package?
a<-installed.packages() packages<-a[,1] is.element(‘boot’,packages) Source:
9
Stop If Version Not High Enough
Do I have a new enough version or can I add logic to my code to make sure that others have a new enough version? packageVersion("stats")[1,1] packageVersion("stats")[1,2] packageVersion("stats")[1,3] # this will stop the script if the stats package is not major version 3 or greater stopifnot(packageVersion("stats")[1,1] >= 3)
10
How are packages managed?
How can I add or delete packages? Add = install.packages(“<package name>”) Delete = remove.packages(“<package name>”) Source:
11
How are packages managed?
What packages are available? p<-available.packages() dim(p) P[1:5,] Source:
12
The Many Arguments of “install.packages()”
install.packages(pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos, type), method, available = NULL, destdir = NULL, dependencies = NA, type = getOption("pkgType"), configure.args = getOption("configure.args"), configure.vars = getOption("configure.vars"), clean = FALSE, Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"), libs_only = FALSE, INSTALL_opts, quiet = FALSE, keep_outputs = FALSE, ...) Source:
13
Walking Through “install.packages()”
A Simple Download from Mirror install.packages(pkgs='dplyr') Specify Your Destination Library install.packages(pkgs='dplyr', lib='/usr/local/lib/R/site-library') Specify a Mirror install.packages(pkgs='dplyr', repos=' Use a Local Package to Install From install.packages('~/dplyr_0.4.3.tar.gz', repos=NULL, type='source') Only Install 64-bit Compatible Version install.packages(pkgs='dplyr', INSTALL_opts="--no-multiarch") (helpful with database drivers which sometimes are hard to install 32 & 64-bit)
14
Installing a Package from “Source” (.tar.gz file)
Find your desired package as a .tar.gz file For example, search “CRAN dplyr” Save to your computer (your desktop), then install from that file using: install.packages('~/dplyr_0.4.3.tar.gz', repos=NULL, type='source')
15
What is the role of CRAN? CRAN stands for “Comprehensive R Archive Network.” CRAN is a network of ftp and web servers around the world that store identical, up-to-date, versions of code and documentation for R.
16
What are the criteria for packages to be carried on CRAN?
project.org/web/packages/policies.html
17
What is Packrat for Package Management?
Creating a packrat enabled project in Rstudio It’s completely isolated!!! Install anything you need Do a weird install: install.packages(pkgs='dplyr', INSTALL_opts="--no-multiarch") # snapshot it packrat::snapshot() # check the status of packages in our project packrat::status() # remove any packages we don’t actually use packrat::clean()
18
Packrat and Colleague Collaboration
If you’re collaborating using a version control system, Packrat will help keep your private libraries in sync. RStudio watches for changes to your Packrat lockfile. When a change from a version control system updates your Packrat lockfile, RStudio will prompt you to apply that change to your private library. For instance, let’s say your collaborator adds a package called argparser as part of a commit. When the packrat.lockfile is updated by the version control system, RStudio will prompt you to bring your library in sync.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.