Learn R Programming

admisc (version 0.41)

inside: Evaluate an Expression in a Data Environment

Description

Evaluate an R expression in an environment constructed from data.

Usage

inside(data, expr, ...)

# S3 method for list inside(data, expr, keepAttrs = TRUE, ...)

Arguments

data

Data to use for constructing an environment a data frame or a list.

expr

Expression to evaluate, often a “compound” expression, i.e., of the form


            {
                a <- somefun()
                b <- otherfun()
                .....
                rm(unused1, temp)
            }
        

keepAttrs

For the list method of inside(), a logical specifying if the resulting list should keep the attributes from data and have its names in the same order. Often this is unneeded as the result is a named list anyway, and then keepAttrs = FALSE is more efficient.

...

Arguments to be passed to (future) methods.

Author

Adrian Dusa

Details

This is a modified version of the base R function within(), with exactly the same arguments and functionality but only one fundamental difference: instead of returning a modified copy of the input data, this function alters the data directly.

Examples

Run this code
mt <- mtcars
inside(mt, hwratio <- hp/wt)

dim(mtcars)

dim(mt)

Run the code above in your browser using DataLab