tests/testthat/test-expandFactors.R

grading <- data.frame(
  teacher = factor(c("Amy", "Amy", "Ben", "Ben", "Cat")),
  gender = factor(c("male", "female", "female", "male", "male")),
  grade = c(75, 80, 45, 50, 65)
)

test_that("expandFactors example works", {

  expect_s3_class(expandFactors(grading), "data.frame")
  expect_equal(nrow(expandFactors(grading)), nrow(grading))
  expect_equal(ncol(expandFactors(grading)), 4)

  expect_equal(
    expandFactors(grading)$teacherBen,
    as.numeric(grading$teacher == "Ben")
  )

})

Try the lsr package in your browser

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

lsr documentation built on Dec. 11, 2021, 9:10 a.m.