R: Unevaluated Expressions (original) (raw)

expression {base} R Documentation

Description

Creates or tests for objects of mode and class "expression".

Usage

expression(...)

is.expression(x)
as.expression(x, ...)

Arguments

... expression: R objects, typically calls, symbols or constants. as.expression: arguments to be passed to methods.
x an arbitrary R object.

Details

‘Expression’ here is not being used in its colloquial sense, that of mathematical expressions. Those are calls (see[call](../../base/help/call.html)) in R, and an R expression vector is a list of calls, symbols etc, for example as returned by [parse](../../base/help/parse.html).

As an object of mode "expression" is a list, it can be subsetted by [, [[ or $, the latter two extracting individual calls etc. The replacement forms of these operators can be used to replace or delete elements.

expression and is.expression are primitive functions.expression is ‘special’: it does not evaluate its arguments.

Value

expression returns a vector of type "expression"containing its arguments (unevaluated).

is.expression returns TRUE if expr is an expression object and FALSE otherwise.

as.expression attempts to coerce its argument into an expression object. It is generic, and only the default method is described here. (The default method callsas.vector(type = "expression") and so may dispatch methods for[as.vector](../../base/help/as.vector.html).) NULL, calls, symbols (see[as.symbol](../../base/help/as.symbol.html)) and pairlists are returned as the element of a length-one expression vector. Atomic vectors are placed element-by-element into an expression vector (without using any names): [list](../../base/help/list.html)s have their type ([typeof](../../base/help/typeof.html)) changed to an expression vector (keeping all attributes). Other types are not currently supported.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language. Wadsworth & Brooks/Cole.

See Also

[call](../../base/help/call.html),[eval](../../base/help/eval.html),[function](../../base/help/function.html). Further,[text](../../graphics/html/text.html), [legend](../../graphics/html/legend.html), and [plotmath](../../grDevices/html/plotmath.html)for plotting mathematical expressions.

Examples

length(ex1 <- expression(1 + 0:9)) # 1
ex1
eval(ex1) # 1:10

length(ex3 <- expression(u, 2, u + 0:9)) # 3
mode(ex3 [3])   # expression
mode(ex3[[3]])  # call
## but not all components are 'call's :
sapply(ex3, mode  ) #  name  numeric  call
sapply(ex3, typeof) # symbol  double  language
rm(ex3)

[Package _base_ version 4.6.0 Index]