Learn R Programming

photon (version 0.3.5)

cmd_options: Format command line options

Description

Helper function to format options for command line calls. The function accepts key-value pairs where the parameter name is the name of the option and the parameter value is the value of the option. Arguments are formatted according to the following rules:

  • If a value is TRUE, add parameter name as flag.

  • If a value is FALSE, do not add parameter name as flag.

  • If a value has length(x) > 1, collapse it as a CSV.

  • If a parameter name is missing, take the value as the flag name.

  • If a parameter name is given, replace underscores with hyphens.

Usage

cmd_options(..., use_double_hyphens = FALSE)

Value

A character vector of formatted command line options that can be used as input to system2 or run.

Arguments

...

Key-value pairs of command line options.

use_double_hyphens

If TRUE, uses double hyphens to designate non-abbreviated command line options and single-hyphens to designate abbreviated ones. If FALSE, always uses single hyphens. Defaults to FALSE as both Java and photon use single hyphens.

Examples

Run this code
# converts R parameters to CMD options
# parameters for the ping command
cmd_options(n = 1, w = 5, "127.0.0.1")

# sometimes, it is necessary to use double hyphens
# options for the docker ps command
cmd_options("ps", all = TRUE, format = "json", use_double_hyphens = TRUE)

# particularly useful together with photon
# the following options can be used for the `photon_opts` argument
# of photon$start()
cmd_options(cors_any = TRUE, data_dir = "path/to/dir")

Run the code above in your browser using DataLab