Learn R Programming

this.path (version 2.2.0)

try.this.path: Attempt to Determine Script's Filename

Description

try.sys.path() attempts to return sys.path(), returning sys.path(original = TRUE) if that fails, returning NA_character_ if that fails as well.

try.env.path(), try.src.path(), try.this.path(), and try.shFILE do the same with env.path(), src.path(), this.path(), and shFILE().

Usage

try.sys.path(contents = FALSE, local = FALSE)
try.env.path(contents = FALSE, n = 0,
             envir = parent.frame(n + 1),
             matchThisEnv = getOption("topLevelEnvironment"))
try.src.path(contents = FALSE, n = 0,
             srcfile = if (n) sys.parent(n) else 0)

try.this.path(contents = FALSE, local = FALSE, n = 0, envir = parent.frame(n + 1), matchThisEnv = getOption("topLevelEnvironment"), srcfile = if (n) sys.parent(n) else 0)

try.shFILE()

Value

character string.

Arguments

contents, local

See ?sys.path().

n, envir, matchThisEnv, srcfile

See ?this.path().

Details

This should NOT be used to construct file paths against the script's directory. This should exclusively be used in the scenario that you would like the normalized path of the executing script, perhaps for a diagnostic message, but it is not required to exist and can be a relative path or undefined.

Examples

Run this code
try.shFILE()
try.this.path()
try.this.path(contents = TRUE)

Run the code above in your browser using DataLab