| Title: | Determine a Script's Filename from Within the Script Itself |
| Description: | A small set of functions wrapping up the call stack and command line inspection needed to determine a running script's filename from within the script itself. |
| Version: | 1.0.1 |
| License: | MIT + file LICENSE |
| URL: | https://github.com/MullinsLab/scriptName |
| BugReports: | https://github.com/MullinsLab/scriptName/issues |
| Imports: | rlang (≥ 0.1.0), purrr (≥ 0.2.3) |
| Suggests: | testthat, devtools |
| RoxygenNote: | 6.1.1 |
| Encoding: | UTF-8 |
| NeedsCompilation: | no |
| Packaged: | 2019-06-19 06:36:17 UTC; tom |
| Author: | Thomas Sibley [aut, cre], University of Washington [cph], Travers Ching [ctb] |
| Maintainer: | Thomas Sibley <trsibley@uw.edu> |
| Repository: | CRAN |
| Date/Publication: | 2019-06-19 07:40:03 UTC |
Determine a script's filename from within the script itself
Description
A small set of functions wrapping up the call stack and command line inspection needed to determine a running script's filename from within the script itself.
Usage
current_filename()
current_source_filename()
current_cli_filename()
Details
current_filename() returns the result of current_source_filename() if
not NULL, otherwise the result of current_cli_filename(), which might be
NULL. You should use this wrapper function rather than the more-specific
functions unless you have a very specific need.
current_source_filename() returns the filename from the most recent call
to source in the current call stack. From within a
sourced script, this is the filename of the script itself.
current_cli_filename() returns the filename found on the command line
invocation of R or Rscript. This may or may not be the caller's file if
there's been an intervening source.
Value
A character vector of length 1 if a script name can be found, otherwise NULL. No manipulation is done to the filename, so it may be relative or absolute.
Examples
# Put this in example.R and try running source("example.R")
# and `Rscript example.R`
filename <- current_filename()
print(filename)