More R Startup — Windows
This page has the following sections:
If you are using RStudio, then you don’t really need to bother with this.
If you start R from the Windows Start menu, then the working directory will be some arbitrary directory. (Arbitrary to you, not to R.)
You probably will want to change the working directory to someplace sensible for the task you are doing.
The easiest way to do that is:
- Select the File menu
- Select “Change dir …”
- Browse through until you get to where you want
If you save when you quit R, then R will write a
.RData file in the working directory.
Once you’ve saved an R workspace in a directory, you can double click on it from the explorer (it will be a file called
.RData but it will probably appear as a blue “R”).
The contents of the
.RData will be used to populate the global environment for the session.
The working directory will be that same directory.
There are a number of R functions that expect a character string containing a file name, which may need to include the path to that file. The form of path names in Windows has an unfortunate collision with R. The separator in the path names is the backslash, which in R is the escape character in characters strings.
You have two choices:
- Use forward slashes instead of the backslashes.
- Put two backslashes where there should be one.
The first option is possible because R does the translation behind the scenes when it knows that it is a path name. The second option works because the way to write “backslash” in an R character string is “backslash-backslash”.
For example, to write the path:
You can write in R either:
You can use the arrow keys to recall previous commands and modify them.
You can use the “escape” key to stop a command that is running. Most commands will stop right away, but some will only stop just before they are done.
If you do a general start, change directory to a place that already has a
.RData file and save when you quit R, then you will have wiped out the objects in the original
Back to top level of Impatient R
Back to More R startup