How to Change the Working Directory in R
If you've ever run an R script and gotten a "file not found" error even though you know the file exists, chances are R is looking in the wrong place. Understanding and controlling your working directory is one of the most practical skills in everyday R use — and it's simpler than it might first appear.
What Is a Working Directory in R?
The working directory is the folder on your computer that R treats as its default location for reading and writing files. When you load a dataset with read.csv("data.csv"), R looks for that file in the working directory. When you save output, it goes there too — unless you specify a full file path.
Think of it as R's "home base" for a given session. Every R session has one active working directory at all times.
To check your current working directory at any point, run: