Returns the directory of the currently active script as a string with a trailing slash. Works across multiple environments: RStudio, command line execution, and generic R sessions.
Details
The function tries three approaches in order:
1. If RStudio is available, uses rstudioapi to get the active document path
2. If running from the command line via Rscript --file=, parses the file argument
3. Falls back to getwd() as a last resort
Note
The fallback to getwd() may not reflect the script's actual location
if the working directory has been changed during the session.