01
How do you install and load a package, and what is the difference between library() and require()?
Show answer
install.packages() downloads from CRAN once; library() loads it in every session. library() throws an error if the package is missing, while require() returns FALSE with a warning, so require() suits conditional checks.
install.packages('dplyr')
library(dplyr)
if (!require('data.table')) {
install.packages('data.table')
library(data.table)
}