Get the Location of the R Script that is Being Sourced/Executed

Provides functions to retrieve the location of R scripts loaded through the source() function or run from the command line using the Rscript command. This functionality is analogous to the Bash shell's ${BASH_SOURCE[0]}. Users can first set the project root's path relative to the script path and then all subsequent paths relative to the root. This system ensures that all paths lead to the same location regardless of where any script is executed/loaded from without resorting to the use of setwd() at the top of the scripts.


scriptloc: Get the location of the R script that is being sourced/executed

Provides functions to retrieve the location of R scripts loaded through the source function or run from the command line using the Rscript command. This functionality is analogous to the Bash shell's ${BASH_SOURCE[0]}. Users can first set the project root's path relative to the script path and then all subsequent paths relative to the root. This system ensures that all paths lead to the same location regardless of where any script is executed/loaded from without resorting to the use of setwd at the top of the scripts.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("scriptloc")

1.0.0 by Naren Chandran Sakthivel, 3 years ago


Browse source code at https://github.com/cran/scriptloc


Authors: Naren Chandran Sakthivel [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests knitr, rmarkdown, prettydoc


See at CRAN