R Language: Get/Set your working directory

0

The `getwd()` function returns the current working directory. The `setwd()` function sets the working directory to the specified path.

Relative paths are paths that are relative to the current working directory. For example, the path `./data` refers to the `data` folder in the current working directory. The path `.../` refers to the parent directory of the current working directory.

Absolute paths are paths that are absolute, meaning that they are not relative to any other directory. For example, the path `/Users/jtleek/data/` refers to the `data` folder in the `jtleek` user's home directory.

Here is an example of how to get and set the working directory in R:

# Get the current working directory

current_wd <- getwd()


# Set the working directory to the `data` folder

setwd("./data")


# Check the current working directory

getwd()

This will set the working directory to the `data` folder in the current working directory.

In Windows, you need to use backslashes instead of forward slashes when specifying absolute paths. For example, the following code will set the working directory to the `Downloads` folder in the `Andrew` user's home directory:

setwd("C:\\Users\\Andrew\\Downloads")

Post a Comment

0Comments
Post a Comment (0)