01 Jan

More R Startup

This page has the following sections:

The R prompt
The search list
Starting R
Customizing the startup

The R prompt

The standard R prompt is:


This indicates that R is ready for your input.

There is also the continuation prompt, which is:


This indicates that R has determined that the line you just entered is not a complete command. If that is a surprise to you, the most common problems are:

  • a mismatch in the number of opening versus closing parentheses
  • a missing quotation mark

The search list

If you give R a command like:

 > mean(mydata)

R needs to find the two objects mean and mydata. It first sees that it needs to evaluate the mean function so it has to find that function. It goes through the search list, in order, looking for a function by that name. It uses the first one it finds. If you have a function called mean in your global environment, it will use that one rather than the mean function that comes with R.

R will then start looking for mydata. If it doesn’t find an object named mydata, then it will produce an error.

Let’s use some visual aids to picture what is happening. We’ll change the command so that it assigns the mean to an object:

 > mymean <- mean(mydata)

The state of the R search list is sketched in Figure 1. When evaluating this command, the first thing that it does is try to find a function called mean. R looks through each place in the search list in order. In this case it finds mean in the last place on the search list.

The next thing it does is to look for mydata. It finds that in the first location.

Figure 1

The function runs as it finds the objects that it needs. Once the function completes, the assignment is done such that a new (or revised) object appears in the first location on the search list. This new state is shown in Figure 2.

Figure 2

The first location in the search list is the only one that can be changed in R. The other locations are read-only.

This overview of the R world has more on this.

Starting R

An important concept related to starting R is “working directory”. This is the directory where R will write items (in particular the .RData file if you save your workspace). It is also the place where it will look for files that you ask for.

You can always see what R thinks is the working directory with the command:

 > getwd()

How R operates is remarkably consistent across different platforms. However, there are slightly different nuances when starting R for different platforms. The platform specific pages talk more about the working directory.

More R Startup — Windows

More R Startup — Linux/Unix

Customizing the startup

You can change what happens when R starts — if you are ambitious enough, there isn’t much about R that you can’t change to suit yourself.

To see how to customize the R startup, do:

 > ?Startup

You can also consult the R Installation and Administration guide.

Back to top level of Impatient R

© Copyright - Burns Statistics