Chapter 3. Navigating the Software


R is a big chunk of software, first and foremost. You will inevitably spend time doing what one does with any big piece of software: configuring it, customizing it, updating it, and fitting it into your computing environment. This chapter will help you perform those tasks. There is nothing here about numerics, statistics, or graphics. This is all about dealing with R as software.

3.1. Getting and Setting the Working Directory


You want to change your working directory. Or you just want to know what it is.


Command line

Use getwd to report the working directory, and use setwd to change it:

> getwd()
[1] "/home/paul/research"
> setwd("Bayes")
> getwd()
[1] "/home/paul/research/Bayes"

From the main menu, select File Change dir... .


From the main menu, select Misc Change Working Directory.

For both Windows and OS X, the menu selection opens the current working directory in a file browser. From there, you can navigate to a new working directory if desired.


Your working directory is important because it is the default location for all file input and output—including reading and writing data files, opening and saving script files, and saving your workspace image. When you open a file and do not specify an absolute path, R will assume that the file is in your working directory.

The initial working directory depends upon how you started R. See Recipe 1.2.

See Also

See Recipe 4.5 for dealing with filenames in Windows. ...

Get R Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.