Learn R Programming

gtools (version 3.9.2)

script_file: Determine the directory or full path to the currently executing script

Description

Determine the directory or full path to the currently executing script

Usage

script_file(fail = c("stop", "warning", "quiet"))

script_path(fail = c("stop", "warning", "quiet"))

Arguments

fail

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.

Value

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).

Functions

  • script_file: Determine the full path of the currently executing script

  • script_path: Determine the directory of the currently executing script

Examples

Run this code
# NOT RUN {
getwd()
commandArgs(trailingOnly = FALSE)

script_file("warning")
script_path("warning")
# }

Run the code above in your browser using DataLab