tests/testthat/test-add_calculated_row.R

test_that("add_calculated_row(x)", {
  expect_snapshot(
    ard_continuous(mtcars, variables = mpg) |>
      add_calculated_row(expr = max - min, stat_name = "range") |>
      apply_fmt_fn()
  )

  expect_snapshot(
    ard_continuous(mtcars, variables = mpg) |>
      add_calculated_row(
        expr =
          dplyr::case_when(
            mean > median ~ "Right Skew",
            mean < median ~ "Left Skew",
            .default = "Symmetric"
          ),
        stat_name = "skew"
      ) |>
      apply_fmt_fn()
  )
})


test_that("add_calculated_row(expr) messaging", {
  expect_snapshot(
    ard_continuous(mtcars, variables = mpg) |>
      add_calculated_row(expr = not_a_stat * 2, stat_name = "this_doesnt_work"),
    error = TRUE
  )
})

test_that("add_calculated_row(by) messaging", {
  expect_snapshot(
    ard_continuous(mtcars, variables = mpg, by = cyl) |>
      add_calculated_row(expr = max - min, stat_name = "range", by = "context"),
    error = TRUE
  )
})

Try the cards package in your browser

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

cards documentation built on Oct. 4, 2024, 1:09 a.m.