How to Change Working Directory in R?

Use `getwd()` to check the current working directory

Use `setwd(“path/to/your/folder”)` to change the working directory

Use a full path, such as `setwd(“C:/Users/Name/Documents”)`

Use a relative path, such as `setwd(“../data”)`

On Windows, use forward slashes `/` or double backslashes `\`

Verify the change with `getwd()`

In RStudio, use `Session` > `Set Working Directory` > `Choose Directory…`

Set the working directory at the start of your script if needed

Suggested for You

Trending Today