Chapter 3. Navigating the Software
Introduction
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
Problem
You want to change your working directory. Or you just want to know what it is.
Solution
- Command line
Use
getwd
to report the working directory, and usesetwd
to change it:>
getwd()
[1] "/home/paul/research" >setwd("Bayes")
>getwd()
[1] "/home/paul/research/Bayes"- Windows
From the main menu, select File → Change dir... .
- OS X
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.
Discussion
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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.