Learn R Programming

this.path (version 0.5.1)

this.path2: Determine Executing Script's Filename

Description

Versions of this.path and this.dir which return NULL or the working directory instead of throwing an error when there is no executing script.

Usage

this.path2(...)
this.dir2(...)

this.dir3(...)

Arguments

arguments passed to this.path.

Value

for this.path2 or this.dir2, the executing script's filename or directory, or NULL if unavailable.

for this.dir3, the executing script's directory, or the working directory if unavailable.

Details

There are a few reasons why there would be no executing script:

  • R is being run from a shell without supplying argument -f FILE or --file=FILE

  • R is being run from a shell under Unix-alikes with option -g Tk or --gui=Tk (GUI ‘Tk’ does not make use of its -f FILE or --file=FILE arguments)

  • R is being run from ‘RStudio’ with no documents open

  • R is being run from ‘Rgui’ with no documents open

The following cases will still throw an error:

  • unable to normalize the executing script's filename

  • using sys.source or testthat::source_file on a file named “clipboard”, “clipboard-128”, or “stdin”

  • active / / source document in ‘RStudio’ / / ‘Rgui’ does not exist (not saved anywhere)

  • in ‘AQUA’, running the current line or selection from an open R script (currently unimplemented)

Examples

Run this code
# NOT RUN {
this.path:::.Rscript(c("--default-packages=NULL", "--vanilla", "-e", "this.path::this.path()" ))
# }
# NOT RUN {
<!-- % essentials::Rscript(c("--default-packages=NULL", "--vanilla"), exprs = "this.path::this.path()" , mustWork = FALSE) -->
# }
# NOT RUN {
this.path:::.Rscript(c("--default-packages=NULL", "--vanilla", "-e", "this.path::this.path2()"))
# }
# NOT RUN {
<!-- % essentials::Rscript(c("--default-packages=NULL", "--vanilla"), exprs = "this.path::this.path()2", mustWork = FALSE) -->
# }
# NOT RUN {
this.path:::.Rscript(c("--default-packages=NULL", "--vanilla", "-e", "this.path::this.dir()"  ))
# }
# NOT RUN {
<!-- % essentials::Rscript(c("--default-packages=NULL", "--vanilla"), exprs = "this.path::this.dir()"  , mustWork = FALSE) -->
# }
# NOT RUN {
this.path:::.Rscript(c("--default-packages=NULL", "--vanilla", "-e", "this.path::this.dir2()" ))
# }
# NOT RUN {
<!-- % essentials::Rscript(c("--default-packages=NULL", "--vanilla"), exprs = "this.path::this.dir2()" , mustWork = FALSE) -->
# }
# NOT RUN {
this.path:::.Rscript(c("--default-packages=NULL", "--vanilla", "-e", "this.path::this.dir3()" ))
# }
# NOT RUN {
<!-- % essentials::Rscript(c("--default-packages=NULL", "--vanilla"), exprs = "this.path::this.dir3()" , mustWork = FALSE) -->
# }

Run the code above in your browser using DataLab