Skip to contents

quo(expr, env) captures expr without evaluating, and returns a qutation object. A quotation has two parts: an expression expr(q) with an environment env(q).

quo_(expr, env) is the normally evaluating version. It constructs a quotation given an expression and environment.

as.quo(x) converts an object into a quotation. Closures, formulas, and single-element dots can be converted this way.

forced_quo(x) captures the expression in its argument, then forces it, returning a quotation with the expression and value.

forced_quo_(val) makes a forced quotation given a value. Specifically it constructs a quotation with the same object in both the expr and value slots, except if is a language object in which case the expr slot is wrapped in quote().

Usage

quo(expr, env = arg_env_(quote(expr), environment()), force = FALSE)

quo_(expr, env, force = FALSE)

env(q)

env(q) <- value

expr(q)

# S3 method for quotation
expr(q)

expr(q) <- value

is.quotation(x)

is.quo(x)

as.quo(x)

forced_quo(x)

forced_quo_(val)

Arguments

expr

An expression. For quo this is taken literally and not evaluated. For quo_ this is evaluated normally.

env

An environment.

force

Whether to evaluate the expression and create a forced quotation.

q

A quotation object.

value

An updated value.

x

Any object.

val

A value.

Value

quo_ and quo return an object of class "quotation".

as.quo returns a quotation.

Details

(Like in writing, an 'expression' may simply be a set of words, but a 'quotation' comes bundled with a citation, to reference a context in which it was said.)

A quo is parallel to a 'promise' which is the data structure R uses to hold lazily evaluated arguments. A quo is different from a promise because it is an immutable data object.

As a data object, a quo does not automatically evaluate like a promise, but can be evaluated explicitly with the methods value or force_. A quo is immutable, so it does not mutate into a "forced" state if you choose to evaluate it; instead force_(q) returns a new object in the forced state.

A function can capture its arguments as quotations using arg.

A dots object is a list of quotations.