Learn R Programming

crunch (version 1.27.0)

derivations: Get or set a derived variable's expression

Description

Get a derived variable's derivation formula as a CrunchExpr with derivation(variable). Set (change) a derived variable's derivation with derivation(variable) <- expression.

Usage

# S4 method for CrunchVariable
derivation(x)

# S4 method for CrunchVariable,ANY derivation(x) <- value

# S4 method for CrunchVariable,`NULL` derivation(x) <- value

# S4 method for CrunchVariable is.derived(x)

# S4 method for CrunchVariable,logical is.derived(x) <- value

Arguments

x

a variable

value

a CrunchExpr to be used as the derivation (for the setter only) or NULL to integrate a derived variable. For is.derived, FALSE can be used to integrate a derived variable.

Value

a CrunchExpr of the derivation for derivation; a logical for is.derived; the variable given in x for is.derived<- returns

Details

To break a derivation link between a derived variable and the originating variable, set the derivation value of the derived variable to NULL with derivation(variable) <- NULL

is.derived can be used to see if a variable is derived or not. Additionally setting a derived variable's is.derived to FALSE will break the derivation link between two variables.

Examples

Run this code
# NOT RUN {
ds$derived_v1 <- ds$v1 + 5

derivation(ds$derived_v1)
# Crunch expression: v1 + 5

derivation(ds$derived_v1) <- ds$v1 + 10
derivation(ds$derived_v1)
# Crunch expression: v1 + 10

is.derived(ds$derived_v1)
# TRUE

# to integrate or instantiate the variable in place (remove the link between
# variable v1 and the derivation) you can:
derivation(ds$derived_v1) <- NULL

# after integrating, the derived variable is no longer derived.
is.derived(ds$derived_v1)
# FALSE
# }

Run the code above in your browser using DataLab