tests/testthat/test-add_l2.R

test_that("combination", {
  
  scdf <- exampleABC
  
  l2 <- data.frame(
    case = c("Marie", "Rosalind", "Lise"),
    gender = c(0,0,2),
    age = c(23,35,12)
  )
  
  combined <- scdf |> add_l2(l2)
  
  expect_s3_class(combined, "scdf")
  expect_equal(scan:::check_scdf(combined), TRUE)
  expect_equal(all(combined[["Rosalind"]]$age == 35), TRUE)
  expect_equal(all(combined[["Lise"]]$gender ==2), TRUE)
  expect_equal(attributes(scdf), attributes(combined))
})

test_that("warnings", {
  
  scdf <- exampleABC
  l2 <- data.frame(
    case = c("Marie", "Heinz", "Lise"),
    gender = c(0,0,2),
    age = c(23,35,12)
  )
  
  expect_warning(scdf |> add_l2(l2))
  
  l2 <- data.frame(
    name = c("Marie", "Rosalind", "Lise"),
    gender = c(0,0,2),
    age = c(23,35,12)
  )
  
  expect_warning(scdf$Marie |> add_l2(l2[1,]))
  
})

Try the scan package in your browser

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

scan documentation built on Aug. 8, 2023, 5:07 p.m.