# NOT RUN {
# Make a sample model:
fit <- lm(Sepal.Length ~ ., data = iris[, -5])
fit_pmml <- pmml(fit)
# Add arbitrary attributes to the 1st 'NumericPredictor' element. The
# attributes are for demostration only (they are not allowed under
# the PMML schema). The command assumes the default namespace.
fit_pmml_2 <- add_attributes(fit_pmml, "/p:PMML/descendant::p:NumericPredictor[1]",
attributes = c(a = 1, b = "b")
)
# Add attributes to the NumericPredictor element which has
# 'Petal.Length' as the 'name' attribute:
fit_pmml_3 <- add_attributes(fit_pmml,
"/p:PMML/descendant::p:NumericPredictor[@name='Petal.Length']",
attributes = c(a = 1, b = "b")
)
# 3 NumericElements exist which have '1' as the 'exponent' attribute.
# Add new attributes to the 3rd one:
fit_pmml_4 <- add_attributes(fit_pmml,
"/p:PMML/descendant::p:NumericPredictor[@exponent='1'][3]",
attributes = c(a = 1, b = "b")
)
# Add attributes to the 1st element whose 'name' attribute contains
# 'Length':
fit_pmml_5 <- add_attributes(fit_pmml,
"/p:PMML/descendant::p:NumericPredictor[contains(@name,'Length')]",
attributes = c(a = 1, b = "b")
)
# }
Run the code above in your browser using DataLab