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
.
Source
The source code of this function was taken from this stackoverflow question.