tests/testthat/test-style_sigfig.R

skip_on_cran()

test_that("correct rounding near thresholds", {
  expect_equal(
    c(1.0001, 1, 0.9999, 0.90000) %>% style_sigfig(digits = 1),
    c("1", "1", "1", "0.9")
  )

  expect_true(
    style_sigfig(-9.98) == "-10"
  )

  expect_equal(
    style_sigfig(seq(from = 9.94, to = 10, by = 0.01)),
    c("9.9", "10", "10", "10", "10", "10", "10")
  )

  expect_true(
    style_sigfig(0.97, digits = 1) == "1"
  )

  vec2 <- c(one = 0.99, two = 0.0005)
  expect_equal(
    attributes(vec2),
    style_sigfig(vec2) %>% attributes()
  )
})

Try the gtsummary package in your browser

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

gtsummary documentation built on July 26, 2023, 5:27 p.m.