Returns the normalised absolute path of the R script that is currently executing. The function tries the following methods in order:
The
--file=command-line argument (set when running viaRscript script.R).The
fileNamevariable in the first call-stack frame (set by some IDEs).The
ofilevariable in the first call-stack frame (set when the script is loaded withsource()).The active document path from
rstudioapi(RStudio only).The source editor path from
rstudioapias a fallback.