05.0 PP 1 6 Getting Started
05.0 PP 1 6 Getting Started
Getting started
This book uses R, which is an open source package for statistical comput-
ing. “Open source” has a number of different meanings; here the important
one is that R is freely available, and its users are free to see how it is writ-
ten, and to improve it. R is based on the computer language S, developed
by John Chambers and others at Bell Laboratories in 1976. In 1993 Robert
Gentleman and Ross Ihaka at the University of Auckland wanted to exper-
iment with the language, so they developed an implementation, and named
it R. They made it open source in 1995, and thousands of people around
the world have contributed to its development.
The R system is mainly command-driven, with the user typing in text and
asking R to execute it. Nowadays most programs use interactive graphical
user interfaces (menus, touchscreens, etc.) instead. So why did we choose
such an old-fashioned way of doing things?
Menu-based interfaces are very convenient when applied to a limited set
of commands, from a few to one or two hundred. However, a command-
line interface is open ended. As we will show in this book, if you want
to program a computer to do something that no one has done before, you
can easily do it by breaking down the task into the parts that make it up,
and then building up a program to carry it out. This may be possible in
some menu-driven interfaces, but it is much easier in a command-driven
interface.
Moreover, learning how to use one command-line interface will give
you skills that carry over to others, and may even give you some insight
into how a menu-driven interface is implemented. As statisticians, it is our
belief that your goal should be understanding, and learning how to program
at a command line will give you that at a fundamental level. Learning to use
a menu-based program makes you dependent on the particular organization
of that program.
There is no question that command-line interfaces require greater
knowledge on the part of the user – you need to remember what to type
to achieve a particular outcome. Fortunately, there is help. We recommend
that you use the RStudio integrated development environment (IDE). IDEs
were first developed in the 1970s to help programmers: they allow you to
edit your program, to search for help, and to run it; when your first attempt
doesn’t work, they offer support for diagnosing and fixing errors. RStudio
is an IDE for R programming, first released in 2011. It is produced by a
Boston company named RStudio, and is available for free use.
In most cases other than this one and certain exercises, we will show
the actual response from R corresponding to the preceding input.1 1 We have used the knitr package so
There are also situations where the code is purely illustrative and is not that R itself is computing the output.
The computations in the text were done
meant to be executed. (Many of those are not correct R code at all; others
with R version 3.2.2 (2015-08-14).
illustrate the syntax of R code in a general way.) In these situations we have
typeset the code examples in an upright typewriter font. For example,
f( some arguments )
r You should do most of your work in the editor, but you can occasionally
type in the console.