[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  expression: Unevaluated Expressions

##  Description

Creates or tests for objects of mode ` "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.

##  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 calls ` as.vector(type = "expression") ` and so may dispatch methods
for ` [ as.vector ](/link/as.vector?package=base&version=3.6.2) ` .) ` NULL `
, calls, symbols (see ` [ as.symbol
](/link/as.symbol?package=base&version=3.6.2) ` ) 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): lists
are changed type to an expression vector (keeping all attributes). Other types
are not currently supported.

##  Details

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

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
](/link/primitive?package=base&version=3.6.2) functions. ` expression ` is
‘special’: it does not evaluate its arguments.

##  References

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

##  See Also

` [ call ](/link/call?package=base&version=3.6.2) ` , ` [ eval
](/link/eval?package=base&version=3.6.2) ` , ` [ function
](/link/function?package=base&version=3.6.2) ` . Further, ` [ text
](/link/text?package=base&version=3.6.2) ` and ` [ legend
](/link/legend?package=base&version=3.6.2) ` for plotting mathematical
expressions.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fexpression&utm_source=r-docs&utm_medium=docs&utm_term=expression&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    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)
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fexpression&utm_source=r-docs&utm_medium=docs&utm_term=expression&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)