Learn R Programming

bruceR (version 0.6.0)

set.wd: Set working directory to where the current file is.

Description

Set working directory to the path of the currently opened file. You can use this function in both .R/.Rmd files and the R console. RStudio is required for running this function.

Usage

set.wd(path = NULL, execute = TRUE, ask = FALSE)

Arguments

path

NULL (default) or a specific path. Default is to extract the path of the currently opened file (can be any type, usually an R or Rmd file).

execute

TRUE (default) or FALSE. Default is to send code setwd("...") to the R console AND execute it.

ask

TRUE or FALSE (default). If TRUE, then you can select a folder with the prompt of a dialog.

Value

Invisibly return the path of the currently opened file.

See Also

setwd

Examples

Run this code
# NOT RUN {
# RStudio is required for running this function.
set.wd()  # set working directory to the path of the currently opened file
set.wd("D:/")  # or any other path (use "/" rather than "\")
set.wd("../")  # set working directory to the parent directory
set.wd(ask=TRUE)  # select a folder with the prompt of a dialog
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab