Chapter 2 Packages
Packages are collections of functions and data sets developed by the community: they increase the power of R by improving existing base R functionalities, or by adding new ones. There are thousands contributed packages available, each with its own suite of functions and built-in datasets. A package first needs to be installed on your pc, and then loaded into the R session, before you can use the functions that the package offers. Packages can be installed on your pc using the install.packages()
function, via the Packages tab in the bottom-right panel of RStudio, or via Tools > Install Packages. Once you have installed a package on your pc you never need to install it again (unless you want to install a new version of the package). To load a package into the R session, you use the library()
function.
Sometimes, different packages contain functions with the same name. In that case, the order in which you load the packages influences which function is being executed once called. Usually, you see warnings printed to the console when this is the case.
You can call a function from a specific package using packagename::functionname()
, for example, the function select
is defined in the dplyr
package as well as the raster
package: in order to explicitly use the select
function from the dplyr
package you can run: dplyr::select()
.