next up previous contents index
Next: Writing, Editing Commands Up: Rgui Previous: Rgui   Contents   Index


Setting Working Directory

Though not necessary, it is a good idea to set your working directory before you start Rgui. To set it, you can right click on your Rgui shortcut, choose Properties, then in the field that is labeled Target Location, you can set it to the directory you want to work in. The default setting is $R_HOME\bin. There are several advantages in doing this, one is that your command history will automatically be set into your current working directory. Another advantage is when you need to read in or write out files, you do not need to specify the absolute path. Take a hypothetical example, suppose I have created a few functions and save them in C:\Temp\foo.R. If I have set the working directory to C:\Temp\ before I start Rgui, then in Rgui I can just type:
source("foo.R")
Note that the "foo.R" is enclosed by double quotes! Further suppose that I have another file called foo.txt, which is a tab delimited table3.1, in C:\Temp\, that looks like:
Index Values
    1    0.9
    2   -0.6
    3   -0.8
    4   -0.9
    5   -2.1
    6   -0.4
    7   -0.2
    8    0.3
    9    0.0
   10   -1.5
Then you can just do the following in Rgui:
fred <- read.table("foo.txt", header = TRUE)
attach(fred)
However, if you do not like the idea of setting and changing your working directory, you can use the file.choose() function. For example, suppose that I did not set the working directory to C:\Temp\ before I opened Rgui, then I can just type:
source(file.choose())
This will bring up a window which allows you to browse through directories. You can then find your foo.R from this chooser window. In the read.table() example above, you can do:
fred <- read.table(file.choose(), header = TRUE)
to find your foo.txt.
next up previous contents index
Next: Writing, Editing Commands Up: Rgui Previous: Rgui   Contents   Index
Ko-Kang Wang 2002-10-10