# NOT RUN {
# Make a sample model:
fit <- lm(Sepal.Length ~ ., data = iris[, -5])
fit_pmml <- pmml(fit)
# The resulting model has data fields but with no 'Interval' or Value'
# elements. This object is already an xml node (not an external text
# file), so there is no need to convert it to an xml node object.
# Add an 'Interval' element node by typing it in
fit_pmml_2 <- add_data_field_children(fit_pmml,
field = "Sepal.Length",
intervals = list(newXMLNode("Interval",
attrs = c(closure = "openClosed", rightMargin = 3)
))
)
# Use helper functions to create list of 'Interval' and 'Value'
# elements. We define the 3 Intervals as ,1] (1,2) and [2,
mi <- make_intervals(
list("openClosed", "openOpen", "closedOpen"),
list(NULL, 1, 2), list(1, 2, NULL)
)
# Define 3 values, none with a 'displayValue' attribute and 1 value
# defined as 'invalid'. The 2nd one is 'valid' by default.
mv <- make_values(
list(1.1, 2.2, 3.3), list(NULL, NULL, NULL),
list("valid", NULL, "invalid")
)
# As an example, apply these to the Sepal.Length field:
fit_pmml_3 <- add_data_field_children(fit_pmml, field = "Sepal.Length", intervals = mi, values = mv)
# Only defined 'Interval's:
fit_pmml_3 <- add_data_field_children(fit_pmml, field = "Sepal.Length", intervals = mi)
# }
Run the code above in your browser using DataLab