| dataStepClass {datastepr} | R Documentation |
An implementation of a SAS datastep in a class
Description
An implementation of a SAS datastep in a class
Usage
dataStepClass
Format
An R6Class generator object
Fields
i-
ibegins at 0 and is incremented for each iteration of the data step.
results-
The
resultsframe is initialized as an empty data frame. It is populated row-wise with each iteration of the data step.
continue-
continueis a marker which signals that the step should continue repeating. Whencontinueis 1, repetition will continue, and whencontinueis 0, repitition will cease. It is initialized to 0.
eval-
evalis initialized as NULL, but will store a pointer to the current evaluation environment. This pointer helps pass the evaluation environment from one iteration of the data step to the next.
Methods
begin(env)-
begindoes three things: imports the environment of the previous step to the current, stores the current environment (or the environment specified), and incrementsiby 1. It takes one argument,envir, which should typically be set toenvironment().
set(dataframe, group_id)-
settakes two arguments: a data frame and an optional unquotedgroup_idvariable. Thisgroup_idvariable must contain a consecutive sequence of natural numbers from 1 to some maximum. In each data step, rows whereimatches thegroup_idvariable (or simply the ith row if no group_id variable is given) are selected, and the slice is split into vectors and imported into the evaluation environment.continueis set to 0 oncesetreaches the maximum value in thegroup_idcolumn, ceasing repetition of the datastep, elsecontinueis set to 1.
set_(dataframe, group_id)-
A standard evaluation version of
set_, in which thegroup_idvariable is included as a string, formula, or lazy object.
output-
outputtakes an optional list argument. Either the list, or, if none is given, all vectors in the evaluation environment are gathered into a data.frame, and this data.frame appended toresults.
end-
endwill, ifcontinueis 1, evaluate the function given within the evaluation environment. Typically, the function given will be the current function: that is, steps are joined recursively.
Examples
step = dataStepClass$new()
frame = data.frame(x = 1:10)
stairs = function() {
step$begin(environment())
step$set(frame)
y = x + 1
step$output()
step$end(stairs)
}
stairs()
step$results