Turn Parsed Expression into Character Form

DESCRIPTION:
Returns a vector of character strings representing the expression.

USAGE:
deparse(expr, short=F)

REQUIRED ARGUMENTS:
expr:
any S-PLUS expression.

OPTIONAL ARGUMENTS:
short:
if TRUE, the deparsed character string may not be the full expression. Instead short forms are used, to keep the total length of the deparsed string within a constant limit. The short form is chiefly useful for trace printing and for labels in situations where space is at a premium.

VALUE:
A character vector, containing the deparsed expression. There will be one element of the character vector for each line of output in dput(expr), unless short is TRUE, in which case only one character string is produced.

DETAILS:
It is typically not necessary to deparse expressions to print them. The process of coercing an expression to mode character usually achieves the same effect, more simply (but note the difference shown in the examples).

The value of deparse is a character vector, with as many elements as there would be lines in the output of dput for the same object. Contrast this with as.character, which guarantees to return a character vector of the same length as the object it got as argument. (This is not likely what you wanted, if you started with an S-PLUS expression object.) The other extreme, more common, is that you want to get a single character string containing the deparsed code. To get this, paste(deparse(expr), collapse = ""\n"") If the string should have no internal new lines, use some other string for collapse(), but remember in this case that the string will not in general parse correctly to get back expr.

This is a generic function; currently there are no methods defined for it.


SEE ALSO:
dput , parse , paste .

EXAMPLES:
z$model <- deparse(model) # save a symbolic form of an argument

# label a plot with the definition of a one-line function f plot(x, f(x), ylab=deparse(f)[2], type="l")

foo <- function(x, y) x^y deparse(foo) [1] "function(x, y)" "x^y" as.character(foo) [1] "" "" "x^y"