Skip to contents

R does not store nor export the path of the currently running script. This is an attempt to circumvent this limitation by applying heuristics (such as call stack and argument inspection) that work in many cases.

Usage

thisfile()

thisfile_source()

thisfile_r()

thisfile_rscript()

thisfile_knit()

Value

The path of the currently running script, NULL if it cannot be determined.

Details

This functions currently work only if the script was sourced, processed with knitr, or run with Rscript or using the --file parameter to the R executable. For code run with Rscript, the exact value of the parameter passed to Rscript is returned.

Author

Kirill Müller, Hadley Wickham, Michael R. Head

Examples

if (FALSE) { # \dontrun{
thisfile()
} # }