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
-
i
begins at 0 and is incremented for each iteration of the data step.
results
-
The
results
frame is initialized as an empty data frame. It is populated row-wise with each iteration of the data step.
continue
-
continue
is a marker which signals that the step should continue repeating. Whencontinue
is 1, repetition will continue, and whencontinue
is 0, repitition will cease. It is initialized to 0.
eval
-
eval
is 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)
-
begin
does three things: imports the environment of the previous step to the current, stores the current environment (or the environment specified), and incrementsi
by 1. It takes one argument,envir
, which should typically be set toenvironment()
.
set(dataframe, group_id)
-
set
takes two arguments: a data frame and an optional unquotedgroup_id
variable. Thisgroup_id
variable must contain a consecutive sequence of natural numbers from 1 to some maximum. In each data step, rows wherei
matches thegroup_id
variable (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.continue
is set to 0 onceset
reaches the maximum value in thegroup_id
column, ceasing repetition of the datastep, elsecontinue
is set to 1.
set_(dataframe, group_id)
-
A standard evaluation version of
set_
, in which thegroup_id
variable is included as a string, formula, or lazy object.
output
-
output
takes 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
-
end
will, ifcontinue
is 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