with
Evaluates an expression in a given context

Description

Evaluates an expression, looking up objects in the expression in the given environment, data.frame, or list. The original data may be modified.

Usage

with(data, expr, ...)
within(data, expr, ...)

Arguments

data a list, data.frame, environment, or integer number.
expr a literal expression. Do not wrap it in the expression function. It should refer to elements of the data argument.
... other arguments are accepted but are currently ignored. Future methods of with(), within() might use them.

Details

Function with is a wrapper for the eval function. In the eval function, data is the envir= argument.
Function within is similar but it will check environment and may modify the original data after evaluation of expression.
Both with and within are generic. Currently, there is no other method for with except for default method. Two methods are implemented for class "data.frame" and "list" of the within function. Note that, there is no default method for within.
Value

withreturns the value of the evaluated expression, where the names in the expression are sought first in the data object. If the data object is a list or a data.frame, the current environment and its parents are also searched. If the data object specifies an environment, that environment and then the parents of that environment are searched.
withinreturns a modified object like data.
See Also
eval.
Examples
with(list(a=1,b=2), a+b)
# returns 3

Package base version 6.0.0-69
Package Index