Learn R Programming

this.path (version 1.2.0)

this.path-package: Get Executing Script's Path, from ‘Rgui’, ‘RStudio’, ‘VSCode’, source(), and Rscript (Shells Including Windows Command Line / / Unix Terminal)

Description

Determine the path of the executing script. Works when running a line or selection in ‘Rgui’, ‘RStudio’, and ‘VSCode’, when using source, sys.source, debugSource in ‘RStudio’, testthat::source_file, and knitr::knit, and when running from a shell.

Arguments

Author

tools:::Rd_package_author("this.path")

Maintainer: tools:::Rd_package_maintainer("this.path")

Details

this.path() returns the normalized path of the executing script.

this.dir() returns the normalized path of the directory in which the executing script is located.

here() constructs file paths relative to the executing script's directory.

path.join(), basename2(), and dirname2() are replacements for file.path(), basename(), and dirname() that better handle drives, network shares, and a few important edge cases.

splitext(), removeext(), ext(), and ext<-() split paths into root and extension, remove extensions, get extensions, and set extensions, respectively.

check.path() and check.dir() check that this.path() and this.dir() are functioning correctly.

as.rel.path() ( or as.relative.path() ) will turn absolute paths into relative paths.

asArgs(), fileArgs(), progArgs(), and withArgs() provide functionality for running scripts with arguments in the same session, as opposed to a new one with Rscript.

is.main() and from.shell() determine if an R script is the main executing script or is run from a shell.

shFILE() extracts FILE from the command line arguments.

tryCatch2() adds argument else. that runs if no error is thrown. This helps to run extra code that is not intended to be protected by the condition handlers.

See Also