setsource: Set Working Directory to the Source File Location

View source: R/setsource.R

setsourceR Documentation

Set Working Directory to the Source File Location

Description

This function sets 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. Note that the R script needs to have a file location before this function can be used.

Usage

setsource(path = TRUE, check = TRUE)

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.

Value

Returns the path of the source file location.

Note

This function uses the documentPath() function in the rstudioapi package by Kevin Ushey, JJ Allaire, Hadley Wickham, and Gary Ritchie (2023).

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

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

See Also

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

Examples

## Not run: 

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

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

## End(Not run)

misty documentation built on Oct. 24, 2024, 5:10 p.m.

Related to setsource in misty...