Learn R Programming

misty (version 0.5.0)

setsource: Set Working Directory to the Source File Location

Description

This function is used to set the working directory to the source file location (i.e., path of the current R script) in RStudio and is equivalent to using the menu item Session - Set Working Directory - To Source File Location.

Usage

setsource(path = TRUE, check = TRUE)

Value

Returns the path of the source file location.

Arguments

path

logical: if TRUE (default), the path of the source file is shown on the console.

check

logical: if TRUE, argument specification is checked.

Author

Takuya Yanagida takuya.yanagida@univie.ac.at

Details

The function documentPath() in the package rstudioapi is used to retrieve the path of the source file. Note that the R script needs to have a file location before this function can be used to set the working directory to the source file location.

References

Ushey, K., Allaire, J., Wickham, H., & Ritchie, G. (2022). rstudioapi: Safely access the RStudio API. R package version 0.14. https://CRAN.R-project.org/package=rstudioapi

See Also

script.close, script.new, script.open, script.save

Examples

Run this code
if (FALSE) {

# Set working directory to the source file location
setsource()

# Set working directory to the source file location
# and assign path to an object
path <- setsource()
path
}

Run the code above in your browser using DataLab