Skip to contents

This function attempts to find the location of the currently running R script. It first tries to identify the script's location based on the command line arguments used to start the script. If the script is being run in an interactive session within RStudio, it falls back to using the rstudioapi to find the file path of the script in the source editor. If the location cannot be determined, it returns NA.

Usage

ScriptLocation()

Source

The source code of this function was taken from this stackoverflow question.

Value

A character string representing the file path of the current R script, or NA if the path cannot be determined.

Examples

# ScriptLocation()