Determine the path of the executing script. Compatible with a few
popular GUIs: ‘Rgui’, ‘RStudio’, ‘VSCode’,
‘Jupyter’, and
‘Rscript
’
(shell). Compatible with several functions and packages:
source()
, sys.source()
, debugSource
()
in ‘RStudio’, testthat::source_file()
, knitr::knit()
, compiler::loadcmp()
, and box::use()
.
tools:::Rd_package_author("this.path")
Maintainer: tools:::Rd_package_maintainer("this.path")
The most important functions from this.path are
this.path()
, this.dir()
, here()
,
and this.proj()
:
this.path()
returns the normalized path of the
executing script.
this.dir()
return the normalized path of the directory
in which the executing script is located.
here()
constructs file paths against the executing
script's directory.
this.proj()
constructs file paths against the executing
project's directory instead of the executing script's directory.
this.path also provides functions for constructing and manipulating file paths:
path.join()
, basename2()
, and
dirname2()
are drop in replacements for
file.path()
, basename()
, and
dirname()
which better handle drives and
network shares.
splitext()
, removeext()
,
ext()
, and ext<-()
split a path into root and
extension, remove a file extension, get an extension, or set an extension
for a file path.
path.split()
, path.split.1()
, and
path.unsplit()
split the path to a file into components.
relpath()
and rel2here()
turn absolute
paths into relative paths.
New additions to this.path include:
LINENO()
returns the line number of the executing
expression in the executing script.
wrap.source()
, inside.source()
,
set.this.path()
, and unset.this.path()
implement this.path()
for any source()
-like functions
outside of source()
, sys.source()
, debugSource
()
in ‘RStudio’, testthat::source_file()
, knitr::knit()
, compiler::loadcmp()
, and box::use()
.
shFILE()
looks through the command line arguments,
extracting FILE from either of the following: -f
FILE or --file=FILE
source()
, sys.source()
, debugSource
()
in ‘RStudio’, testthat::source_file()
, knitr::knit()
, compiler::loadcmp()
, box::use()
R.from.shell