Learn R Programming

box (version 1.0.0)

path: Get a module<U+2019>s path

Description

The following functions retrieve information about the path of the directory that a module or script is running in.

Usage

path(mod)

base_path(mod)

script_path()

knitr_path()

shiny_path()

Arguments

mod

a module environment or namespace.

Value

path returns a character string containing the module<U+2019>s full path.

base_path returns a character string containing the module<U+2019>s base directory, or the current working directory if not invoked on a module.

script_path returns a character string that contains the directory in which the calling R code is run. See ‘Details’.

knitr_path returns the directory in which the currently knit document is run, or NULL if not called from within a knitr document.

shiny_path returns the directory in which a Shiny application is running, or NULL if not called from within a Shiny application.

Details

script_path takes a best guess at a script<U+2019>s path, since R does not provide a sure-fire way for determining the path of the currently executing code. The following calling situations are covered:

  1. Path explicitly set via set_script_path

  2. Path of a running document/application (knitr, Shiny)

  3. Code invoked as Rscript script.r

  4. Code invoked as R CMD BATCH script.r

  5. Script run interactively (use getwd())