Packages

Nelson Areal

Nomenclature

In R the place where a package is installed is called library.

R does not automatically load all the installed packages.

Loaded packages

To get a list of all loaded packages:

path.package()

It also gives the path where those packages are in your hard drive.

Installed packages

To get the list of installed packages use:

installed.packages()

Installing packages

We can install packages using the RStudio or the install.packages() command:

install.packages("dplyr")

If we want to install more than one package we need provide a vector with the package names.

install.packages(c("dplyr", "readxl", "readr"))

Whenever there is a major release of R x.y you’ll need to re-install the packages.

R tries to install binary versions of the packages, and only when they are not available you’ll be prompted to compile them localy. This is easier on a Mac or linux machine.

Installing packages

By default packages are installed from The Comprehensive R Archive Network (CRAN).

You can get a list of all available packages in here.

CRAN Task Views has curated lists of packages per topic making it a great starting point to learn about the most commonly used packages for a given task.

Removing packages

remove.packages("dplyr")

Loading packages

An installed package cannot be used before being loaded.

To load and attach a package we use library():

library("dplyr")

When function names are masked we can get to desired function using: libraryname::functionname()

Unloading packages

To unload/detach a package we use detach():

detach(package:dplyr)

Listing the package functions

To get the list of all functions from a package:

library(help=dplyr)

It also provides useful additional information.

Next

Watch the video below.