R/script_file.R
script_file.RdDetermine the directory or full path to the currently executing script
character, one of "stop", "warning", "quiet". specifying what should be done when the script path cannot be determined: "stop" causes an error to be generated, "warn" generates a warning message and returns NA, "quiet" silently returns NA.
These function should work with Rscript, source(),
Rmarkdown RStudio's "Run selection", and the RStudio
Console.
A character scalar containing the full path to the currently
executing script file (script_file) or its directory
(script_path). If unable to determine the script path, it generates
a warning and returns "" (empty string).
script_file(): Determine the full path of the currently executing
script
script_path(): Determine the directory of the currently executing script
getwd()
#> [1] "/data/user-homes/elizabethb/projects/prism-pkgdocs-build/installed-pkgs/priority-3/gtools_3.9.5/docs/reference"
commandArgs(trailingOnly = FALSE)
#> [1] "/opt/R/4.5.1/lib/R/bin/exec/R"
#> [2] "--slave"
#> [3] "--no-save"
#> [4] "--no-restore"
#> [5] "-f"
#> [6] "/tmp/Rtmp2I7TQr/callr-scr-2c0840795735f6"
script_file("warning")
#> [1] "/tmp/Rtmp2I7TQr/callr-scr-2c0840795735f6"
script_path("warning")
#> [1] "/tmp/Rtmp2I7TQr"