In R statistical procedures are organized into groups of related functions and are called packages. The base version of R ships with built-in packages, which are loaded by default when we start R. Many more functions, which drastically extend the functionality of base R, are available from packages developed by users in the R community (contributed packages). Anyone can write and upload a properly formatted contributed package to the CRAN servers.
In order to download a contributed package and make use of therein
provided functions, we have to type
install.packages("PACKAGE-NAME")
into the R console (Note
the quotation marks!). For example, in order to download the quite
popular ggplot2
package, a package for data visualization,
we type
install.packages("ggplot2")
Once downloaded, we can access the bundle of new functions within R
by typing library(PACKAGE-NAME)
. Note, that this time we
write the package name without quotation marks! With respect to our
example from above, we write:
library(ggplot2)
If everything worked out fine and we do not get any error messages,
all the functions of the ggplot2
package are now available
within R. It is worth noting that in some cases you do not want to load
the whole package, but you just want to use one particular function of a
package. If you already downloaded the package, you may access a
function of a package by using the ::
operator in the form
of PACKAGE-NAME::FUNCTION-OF-INTEREST(...)
. With respect to
the example from above, we make use of the ggplot()
function from the ggplot2
package by typing the following
command into your R console.
ggplot2::ggplot(...)
Citation
The E-Learning project SOGA-R was developed at the Department of Earth Sciences by Kai Hartmann, Joachim Krois and Annette Rudolph. You can reach us via mail by soga[at]zedat.fu-berlin.de.
Please cite as follow: Hartmann, K., Krois, J., Rudolph, A. (2023): Statistics and Geodata Analysis using R (SOGA-R). Department of Earth Sciences, Freie Universitaet Berlin.