scriptloc {scriptloc} | R Documentation |
Get location of script in a fashion analagous to $BASH_SOURCE[0]
Description
There are two ways in which code from an R file can be executed: through the command line by invoking Rscript or by using the source() function. This function tries to see if either of the methods were used, and if not, deduces that the function is being called from an interactive session and therefore returns NULL.
Usage
scriptloc()
Value
Returns either a single string with path to the file being executed, or NULL
Examples
writeLines("library(scriptloc); script_path <- scriptloc(); print(script_path)", "example.R")
source("example.R")
file.remove("example.R")
[Package scriptloc version 1.0.0 Index]