Packages

The first introductory example uses the Heights data in the alr4 package. You need to install the alr4 package before you can use it – you only need to do this once.

Suppose you try to use the alr4 package without having installed it. You would type library(alr4) and you would get something like:

Error in library(alr4) : there is no package called ‘alr4’

Installing a package

To install the package, use one of the following:

  1. In RStudio click on the “Tools” menu and then “Install Packages…” and type in the name of the package (alr4 in this case) to install it

  2. Or in the RGui click on the “Packages” menu and then “Install Package(s)…” and choose a mirror site to use and the package to install

  3. Or in an R console window type something like: install.packages("alr4")

You only need to install a package once.

Loading a package

To load the alr4 package:

library(alr4)
## Loading required package: car
## Loading required package: effects
## 
## Attaching package: 'effects'
## The following object is masked from 'package:car':
## 
##     Prestige

The Heights data, which is part of alr4, is now available:

head(Heights)
##   mheight dheight
## 1    59.7    55.1
## 2    58.2    56.5
## 3    60.6    56.0
## 4    60.7    56.8
## 5    61.8    56.0
## 6    55.5    57.9

You need to load a package once per R session.

To check which packages are currently loaded:

search()
##  [1] ".GlobalEnv"        "package:alr4"      "package:effects"  
##  [4] "package:car"       "package:stats"     "package:graphics" 
##  [7] "package:grDevices" "package:utils"     "package:datasets" 
## [10] "package:methods"   "Autoloads"         "package:base"