Packages
Packages are a set of functions, constants, and/or data developed by the community that add functionality to R.
In this section, we look at where to find packages and how to install them.
Looking for packages
- Package finder
- Your peers and the literature
Package documentation
Managing R packages
R packages can be installed, updated, and removed from within R:
install.packages("<package_name>", repos="<url-cran-mirror>")
remove.packages("<package-name>")
update_packages()
repos
argument: chose a CRAN mirror close to the location of your cluster or use https://cloud.r-project.org/.
The first time you install a package, R will ask you whether you want to create a personal library in your home directory. Answer yes
to both questions. Your packages will now install under ~/
.
Some packages require additional modules to be loaded before they can be installed. Other packages need additional R packages as dependencies. In either case, you will get explicit error messages. Adding the argument dependencies = T
helps in the second case, but you will still have to add packages manually from time to time.
Loading packages
To make a package available in an R session, you load it with the library()
function.
Example:
library(readxl)
Alternatively, you can access a function from a package without loading it with the syntax: package::function()
.
Example:
::read_excel("file.xlsx") readxl