# INSTALLING R

3

and we will use the prompt R> for the display of the code examples throughout this book.

Essentially, the R system evaluates commands typed on the R prompt and returns the results of the computations. The end of a command is indicated by the return key. Virtually all introductory texts on R start with an example using R as pocket calculator, and so do we:

# R> x <- sqrt(25) + 2

This simple statement asks the R interpreter to calculate ^{√}25 and then to add 2. The result of the operation is assigned to an R object with variable name x. The assignment operator <- binds the value of its right hand side to a variable name on the left hand side. The value of the object x can be inspected simply by typing

# R> x

[1] 7

which, implicitly, calls the print method: R> print(x)

[1] 7

1.2.2 Packages The base distribution already comes with some high-priority add-on packages,

namely

Matrix

mgcv

rpart

survival

KernSmooth

MASS

base

boot

class

cluster

codetools

compiler

datasets

foreign

grDevices

graphics

grid

lattice

methods

nlme

nnet

parallel

spatial

splines

stats

stats4

tcltk

tools

utils

The packages listed here implement standard statistical functionality, for ex- ample linear models, classical tests, a huge collection of high-level plotting functions or tools for survival analysis; many of these will be described and used in later chapters.

Packages not included in the base distribution can be installed directly from the R prompt. At the time of writing this chapter, 6154 user contributed packages covering almost all fields of statistical methodology were available.

Given that an Internet connection is available, a package is installed by supplying the name of the package to the function install.packages. If, for example, add-on functionality for robust estimation of covariance matrices via sandwich estimators is required (for example in Chapter ??), the sandwich package (Zeileis, 2004) can be downloaded and installed via