Learn R Programming

Rapp (version 0.3.0)

run: Run an R app.

Description

Run an R app.

Usage

run(app, args = commandArgs(TRUE))

Value

Mainly called for its side effect. For advanced or testing use, it invisibly returns the evaluation environment where the app’s expressions ran. If the app did not run (for example, when --help is used), it returns NULL

invisibly.

Arguments

app

A filepath to an Rapp.

args

character vector of command line args.

Details

See the package README for full details. https://github.com/r-lib/Rapp

Examples

Run this code
# For the example, place 'Rapp', the package examples, and 'R' on the PATH
old_path <- Sys.getenv("PATH")
Sys.setenv(PATH = paste(system.file("examples", package = "Rapp"),
                        system.file("exec", package = "Rapp"),
                        R.home("bin"),
                        old_path,
                        sep = .Platform$path.sep))

# Here is an example app:
# flip-coin.R
writeLines(readLines(
  system.file("examples/flip-coin.R", package = "Rapp")))

if(.Platform$OS.type != "windows") {
  # on macOS and Linux, you can call the app directly
  system("flip-coin.R")
  system("flip-coin.R --n 3")
} else {
  # On windows, there is no support for shebang '#!' style executables
  # but you can invoke 'Rapp' directly
  system("Rapp flip-coin.R")
  system("Rapp flip-coin.R --n 3")
}

# restore PATH
Sys.setenv(PATH = old_path)

Run the code above in your browser using DataLab