1.2 Packages

1.2.1 Installing Packages

Installing packages from CRAN is very simple. If you find you need a (fictional) package called packagename, you install it with the function install.packages(), like so,

install.packages("packagename")

1.2.2 Using and Loading Packages

Once you have installed a package, there is one more step before you can use the functions it contains. Every time you restart R, you have to tell R which packages you want to access. The reason for this is if R always loads every package you install, R would eventually slow down and take an large amount of memory as you install more and more packages.

If we want to load an entire package, you can use the library() function. Here we load the (fictional) package packagename,

library(packagename)

If we only want to use one or two functions from a package, it is often more efficient to not use library, but instead to remind R which package the function comes from. Here we want to use the (fictional) function func() from the (fictional) packagename package,

packagename::func()

1.2.3 Required Packages

For this series of tutorials, we will make use of some common packages from CRAN. Please execute the following code to install all the required packages,

install.packages(c("tidyverse", "scatterD3", "DescTools", "GGally", "BSDA", "asbio"))

or the following code if you want to install each package individually,

install.packages("tidyverse")
install.packages("scatterD3")
install.packages("DescTools")
install.packages("GGally")
install.packages("BSDA")
install.packages("asbio")