nseval (version 0.4)

quo: Quotation objects.

Description

quo captures its argument literally, that is, without evaluating, and constructs a quotation. A quotation has two parts: an expression expr(q) with an environment env(q). (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.)

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.

Usage

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

quo_(expr, env, force = FALSE)

env(q)

# S3 method for quotation env(q)

env(q) <- value

# S3 method for quotation env(q) <- value

expr(q)

# S3 method for quotation expr(q)

expr(q) <- value

# S3 method for quotation expr(q) <- value

is.quotation(x)

as.quo(x)

# S3 method for function as.quo(x)

# S3 method for quotation as.quo(x)

# S3 method for dots as.quo(x)

# S3 method for formula as.quo(x)

# S3 method for lazy as.quo(x)

# S3 method for default as.quo(x)

Arguments

expr

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

force

Immediately evaluate the expression and create a forced quotation, i.e. one that stores an expression and value, but no environment.

q

A quotation object.

value

An updated value.

x

Any object.

Value

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

as.quo returns a quotation.

Details

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.

A function can capture its arguments as quotations using arg.

A dots object is a list of quotations.