Learn R Programming

this.path (version 1.4.0)

shFILE: Get FILE Provided to R by a Shell

Description

Look through the command line arguments, extracting FILE from either of the following: -f FILE or --file=FILE

Usage

shFILE(original = FALSE, for.msg = FALSE, default, else.)

Value

character string, or default if FILE was not found.

Arguments

original

TRUE, FALSE, or NA; should the original or the normalized path be returned? NA means the normalized path will be returned if it has already been forced, and the original path otherwise.

for.msg

TRUE or FALSE; do you want the path for the purpose of printing a diagnostic message / / warning / / error? for.msg = TRUE will ignore original = FALSE, and will use original = NA instead.

default

if FILE is not found, this value is returned.

else.

missing or a function to apply if FILE is found. See tryCatch2() for inspiration.

See Also

this.path(), here()

Examples

Run this code
FILE <- tempfile(fileext = ".R")
this.path:::write.code({
    this.path:::withAutoprint({
        shFILE(original = TRUE)
        shFILE()
        shFILE(default = {
            stop("since 'FILE' will be found, argument 'default'\n",
                " will not be evaluated, so this error will not be\n",
                " thrown! you can use this to your advantage in a\n",
                " similar manner, doing arbitrary things only if\n",
                " 'FILE' is not found")
        })
    }, spaced = TRUE, verbose = FALSE, width.cutoff = 60L)
}, FILE)
this.path:::Rscript(
    c("--default-packages=this.path", "--vanilla", FILE)
)
unlink(FILE)


for (expr in c("shFILE(original = TRUE)",
               "shFILE(original = TRUE, default = NULL)",
               "shFILE()",
               "shFILE(default = NULL)"))
{
    cat("\n\n")
    this.path:::Rscript(
        c("--default-packages=this.path", "--vanilla", "-e", expr)
    )
}

Run the code above in your browser using DataLab