Command: Compose R Commands from Character Strings

View source: R/Command.R

CommandR Documentation

Compose R Commands from Character Strings

Description

Command simplifies the process of composing text-string versions of R commands, suitable, e.g., for doItAndPrint, from character strings representing a function name, arguments to the function, and (optionally) the name of a variable to be assigned the value returned by the function; all of the arguments to Command are text strings.

Usage

Command(fun, ..., to)
Q(string)

Arguments

fun

character string representing the name of a function to be called; e.g., "lm".

...

zero or more named or unnamed arguments for the function; e.g. (for lm), "y ~ x1 + x2", data = "Dataset"; if a named argument is given the value "", NULL, or NA, then the corresponding argument is suppressed in the generated command.

to

optionally the text name of variable to be assigned the value returned by the function; e.g. (for the lm example), to = "model1".

string

a character string (or an object that can be coerced to a character string).

Value

Command returns the text representation of an R command, e.g., "model1 <- lm(y ~ x1 + x2, data=Dataset"; Q places quotation marks around string, e.g., Q("Annual Income"), and is meant to be used when an argument to Command should be quoted (see the last example below).

Author(s)

John Fox

See Also

doItAndPrint, justDoIt, logger.

Examples

Command("lm", "prestige ~ income + education", data="Duncan", weights="imp", to="model")
Command("lm", "prestige ~ income + education", data="Duncan", weights=NULL, to="model")
Command("plot", x="income", y="prestige", xlab=Q("Income"), ylab=Q("Prestige"))

Rcmdr documentation built on Sept. 28, 2023, 5:08 p.m.