Learn R Programming

Rdrools (version 1.0.3)

runRules: Apply a set of rule transformations to a data frame

Description

This function is the core of the Rdrools package. Rules are applied on an input data frame and the results are returned as the output of the function. The columns on which the rules need to be applied have to be provided explicitly. Additionally, the new columns that would be created based on the rules have to be provided explicitly as well. The rules engine picks up a row from the dataframe, applies the transformation to it based on rules provided and saves the result in an output dataframe.

Usage

runRules(rules.session, input.df)

Arguments

rules.session

a session of the rules engine created using the the rulesSession

input.df

a dataframe consisting of a set of rows you wish to transform, and columns you wish to use in the transformation

Value

output.df

a dataframe which is the result of transformations applied to the input dataframe(input.df), the columns being the list provided through the output.columns parameter in rulesSession.

Warning

Transformation policy Transformations are applied row by row, iteratively. That is to say, all inputs required for a rule transformation should be present in columns as a part of that row itself. Each row should be considered independent of another; all input values required for a transformation should be available in that row itself. The expectation from rules engines are often misplaced. Column Mismatch Please make sure that the list of output columns provided through the output.columns parameter is exhaustive. Any additional column which is created through the rules transformation but is not present in the list would inhibit proper functioning. In most cases, an error should be thrown.

Details

If you are not familiar with the drools file format, please have a look at the references provided in the Rdrools man page. More details on how conflicting rules are resolved using either salience or the Reete algorithm are also present in the references.

See Also

Rdrools, rulesSession

Examples

Run this code
# NOT RUN {
library(Rdrools)
data(class)
data(rules)
input.columns<-c('name', 'class', 'grade', 'email')
output.columns<-c('address', 'subject', 'body')
rules.session<-rulesSession(rules, input.columns, output.columns)
output.df<-runRules(rules.session, class)

# }

Run the code above in your browser using DataLab