tests/testthat/test-addAttributes.R

test_that("`addAttributes()` correctly adds the attr list", {
  df   <- data.frame(num = 1:6)
  atts <- list(A = 1:10, B = LETTERS)
  new  <- attributes(addAttributes(df, atts))
  expect_type(new, "list")
  expect_named(new, c("names", "class", "row.names", names(atts)))
  expect_equal(new$A, 1:10)
  expect_equal(new$B, LETTERS)
})

test_that("`addAttributes()` throws correct errors and messages", {
  expect_error(
    addAttributes(1:10L, list(A = 1:10)),
    "`data` must be a data frame, tibble, or similar.",
  )
  df <- data.frame(num = 1:6)
  expect_error(
    addAttributes(df, c(A = 1)),
    "`new.atts` must be a *named* list.", fixed = TRUE
  )
  expect_error(
    addAttributes(df, list(1:10)),
    "`new.atts` must be a *named* list.", fixed = TRUE
  )
})

Try the SomaDataIO package in your browser

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

SomaDataIO documentation built on April 4, 2025, 2:14 a.m.