tests/testthat/test_add_attributes.R

test_that("test add_attributes function follows the xml path properly", {
  model0 <- lm(Sepal.Length ~ ., data = iris[, -5])
  model <- pmml(model0)

  # add arbitary attributes on the 3rd 'NumericPredictor' element
  # with an attribute 'exponent'=1
  model <- add_attributes(model,
    "/p:PMML/descendant::p:NumericPredictor[@exponent='1'][3]",
    attributes = c(a = 1, b = "b")
  )

  test <- xmlToList(model)$RegressionModel$RegressionTable[[3]]
  expect_equal(test[[1]], "Petal.Width")
  expect_equal(test[[4]], "1")
  expect_equal(names(test)[4], "a")
  expect_equal(test[[5]], "b")
})

Try the pmml package in your browser

Any scripts or data that you put into this service are public.

pmml documentation built on March 18, 2022, 5:49 p.m.