Basic skills in R: Installation, activation and use of R packages
Installing and activating packages within RStudio
Some analyses require installing a special package to access the appropriate functions and code.
In this theory page we demonstrate how to install and activate a package in RStudio; in R itself you use the function install.packages()
to install a package.
Packages
Click " Install " and you will get a pop-up window where you can search for the package you want to download.
Installer Popup
Here we entered car
; this is a commonly used package in R - hereafter we click on " Install ". Then, R automatically downloads all files that make up the package.
R automatically installs "dependencies", which are supporting packages that are part of package car
. Because car
is a versatile package, it has many dependencies. Smaller packages have fewer or no dependencies.
When the download is ready, you cannot immediately use the associated functions and code. This is because R has only downloaded the package, but not yet activated it. To activate the package you use the function library()
.
Below is an example:
Activating the package car
If you do not receive any further notification in the console, you can then use the functions and code from the package, which is now also in the list of activated packages of R:
User library