refset (version 0.1.1)

wrap: 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

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, is.parcel, unwrap_as, wrapset

Examples

Run this code
# NOT RUN {
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)

# }

Run the code above in your browser using DataCamp Workspace