source()
, and Rscript
(Shells Including
Windows Command Line / / Unix Terminal)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.
tools:::Rd_package_author("this.path")
Maintainer: tools:::Rd_package_maintainer("this.path")
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.
source
, sys.source
, debugSource
in ‘RStudio’, testthat::source_file
, knitr::knit
R.from.shell