tests/testthat/test-replace_Inf.R

test_that("replace_inf works", {
  x <- 1:5
  x[3] <- Inf # converts to double
  expect_identical(vec_replace_inf(x, 3), as.double(1:5))
  df <- tibble(
    geo_value = letters[1:5], time_value = 1:5,
    v1 = 1:5, v2 = c(1, 2, Inf, -Inf, NA)
  )

  suppressPackageStartupMessages(library(dplyr))
  ok <- c("geo_value", "time_value")
  df2 <- df %>% mutate(across(!all_of(ok), ~ vec_replace_inf(.x, NA)))
  expect_identical(df[, 1:3], df2[, 1:3])
  expect_identical(df2$v2, c(1, 2, NA, NA, NA))
})
cmu-delphi/epipredict documentation built on March 5, 2025, 12:17 p.m.