deparse
Turn a Parsed Expression into Character Form
Description
Returns a vector of character strings representing the input expression.
Usage
deparse(expr, width.cutoff = 60L,
backtick = mode(expr) %in% c("call", "expression", "(", "function"),
control = c("keepInteger", "showAttributes", "keepNA"), nlines = -1L)
Arguments
expr |
any expression.
|
width.cutoff |
the maximum number of characters on a line. Must be between 20 and 500.
the default is 60. Note that a line might be longer if deparse
fails to find a good way to split the expression.
|
backtick |
a logical flag. If TRUE, symbol names are escaped with backticks
when needed. If FALSE, symbol names are not escaped. This
technique can be useful (and more readable) when you want the result
to be displayed as a label, but it is not possible to parse the
result.
|
control |
a vector of character strings that indicate which kind of options you are
trying to set. A valid combination includes the following:
- "all"
- "keepInteger"
- "quoteExpressions"
- "showAttributes"
- "useSource"
- "warnIncomplete"
- "delayPromises"
- "keepNA"
- "S_compatible"
- "noSplitLines"
Note that "all" specifies all options on this list except
"delayPromises", "S_compatible", and "noSplitLines".
- If mode(expr) is "call" or "name", and the control with
"quoteExpressions" is set, the result is surrounded by
"quote()".
- If mode(expr) is "call", and control with
"S_compatible" is set, the integer changes to double.
|
nlines |
the maximum number of lines to return.
|
Details
Usually, it is not necessary to deparse expressions to print them.
The process of coercing an expression to mode "character" with
the as.character function, for example, usually achieves the
same effect in a simpler way. However, there are differences between
deparse and as.character, as shown in the examples below.
The value of deparse is a character vector that has as many
elements as there are lines in the output from dput(expr).
Contrast this with as.character, which returns a character
vector the same length as the input object. This is most likely not what
you want if you started with an expression object.
The other extreme is if you want a single character string containing
deparsed code. To get this, use the command
paste(deparse(expr), collapse = "\n"). You can use another
value for the collapse argument if you do not want newlines
in the string, but the string might not always parse correctly to
recover expr.
Value
returns a character vector containing the deparsed expression.
Each element of the character vector corresponds to a line of
output from dput(expr).
Differences between TIBCO Enterprise Runtime for R and Open-source R
- TIBCO Enterprise Runtime for R has the extra control parameter noSplitLines.
- In TIBCO Enterprise Runtime for R, deparse currently supports only the control parameters 'keepInteger', 'keepNA', 'showAttributes', 'useSource', and (the TIBCO Enterprise Runtime for R-specific) 'noSplitLines'.
See Also
Examples
ex <- parse(text="mean(1:10)")
deparse(ex)
# [1] "expression(mean(1:10))"
f <- function(x, y=1) { x+y }
deparse(f)
# [1] "function(x, y = 1) {" " x + y" "}"