Wrap an expression and its environment into a parcel.

Description

Refsets (and other active bindings) cannot be passed as function arguments, since doing so makes a copy. wrap allows you to pass arbitrary expressions between functions and records where they are ultimately evaluated.

Usage

1
wrap(expr, env = parent.frame())

Arguments

expr

an R expression

env

environment in which expr is to be evaluated

Value

An object of class 'parcel', with components expr and env.

See Also

Other wrapping functions: contents, contents<-; is.parcel; unwrap_as; wrapset

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
dfr <- data.frame(a=1:4, b=1:4)
rs %r% dfr[1:2,]
parcel <- wrap(rs)
f <- function (parcel) contents(parcel) <- contents(parcel)*2
f(parcel)
contents(parcel)
dfr

parcel <- wrap(x^2) # non-refset use
x <- 3
f <- function(parcel) {x <- 10; contents(parcel)}
f(parcel)