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. When continue is 1, repetition will continue, and when continue 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 increments i by 1. It takes one argument, envir, which should typically be set to environment().

set(dataframe, group_id)

set takes two arguments: a data frame and an optional unquoted group_id variable. This group_id variable must contain a consecutive sequence of natural numbers from 1 to some maximum. In each data step, rows where i matches the group_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 once set reaches the maximum value in the group_id column, ceasing repetition of the datastep, else continue is set to 1.

set_(dataframe, group_id)

A standard evaluation version of set_, in which the group_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 to results.

end

end will, if continue 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

[Package datastepr version 0.0.2 Index]