1. Introduction to the R Environment

1.1. The Interface

The R environment is a general command line driven application. It has a number of default functions and abilities that help make it a useful tool for performing calculations. The environment can be extended to provide more capabilities which has helped to make it an ideal tool for performing statistical analyses.

Here we focus on the basics of using R. In later chapters more details are provided to demonstrate how to accomplish specific tasks. The basic idea is that you can type commands and enter them, and the environment will parse, react, and execute the commands that are given to it. The examples throughout these pages take the form given below:

> a <- 1
> b <- 2
> ls()
[1] "a" "b"
> a+b
[1] 3

In the example above, I typed in the commands such as a <- 1. The R environment included the output and the symbol >.

In the previous example you may not be familiar with the commands given. Whenever you see a command that you do not understand you can get help using a number of different commands. One command is the help command. It takes at least one argument. That argument can be the name of a command or it can be a set of symbols in quotes.

> help(ls)
> help("<-")

There are other commands that can be used to obtain help. One is the use of the ? symbol. It works the same way as the help command except that the argument is not enclosed in parentheses. Another command help.search can be used to perform a text based search, and the argument should be a term enclosed in quotes.

> ? ls
> ? "<-"
> help.search("assignment")

In addition to the large number of commands that are recognized there are also a small number of keyboard events that are recognized. In particular, the up and down arrows can be used to move up and down in the list of commands that have been previously entered. You can use the arrow keys to move back to a previous command and enter it without having to retype the command.

Another key that is useful is the TAB key. It can be used to complete a partial command that has been entered at the command line. For example, if you type in the letter l and then hit the tab key once there will not be any reaction. This is because there is not a unique command that can be completed. If you type the TAB key a second time you will get a list of potential commands that can be called.

> l
l10n_info             legend                license               loadMethod            log2
labels                length                limitedLabels         loadNamespace         logLik
labels.default        length.POSIXlt        line                  loadedNamespaces      logb
lag                   length<-              linearizeMlist        loadhistory           logical
lag.plot              length<-.factor       lines                 loadingNamespaceInfo  loglin
languageEl            letters               lines.default         loadings              longley
languageEl<-          levels                list                  local                 lower.tri
lapply                levels.default        list.dirs             localeToCharset       lowess
layout                levels<-              list.files            locator               ls
layout.show           levels<-.factor       list2env              lockBinding           ls.diag
lazyLoad              lfactorial            listFromMethods       lockEnvironment       ls.print
lazyLoadDBexec        lgamma                listFromMlist         loess                 ls.str
lazyLoadDBfetch       lh                    lm                    loess.control         lsf.str
lbeta                 library               lm.fit                loess.smooth          lsfit
lchoose               library.dynam         lm.influence          log                   lynx
lcm                   library.dynam.unload  lm.wfit               log10
ldeaths               licence               load                  log1p

Another useful key event is to clear the screen by pressing the control key and the l key at the same time. If you press this combination of keys together at the same time the screen will be cleared, and you will start with a fresh screen.

Another common key event is to press the control key and the r key at the same time. This can be used to scroll through the previous commands that have been entered that start with the same letters as you have typed. For example, if you type the letter l and then hit the control-r key repeatedly you will get a list of the commands that you have already entered that start with the letter l.

(reverse-i-search)`l': ls()

Finally, if you wish to quit the R environment you can either type in the command q() or hold down the control key and the d key at the same time.

1.2. Assignment

Basics of assignment here.


1.3. Directory Settings

getwd() setwd()

1.4. The R Interface

basics of the R interface here

arrow keys tab key


save() load()



1.5. Start Up


1.6. Packages

basics about packages