tests/testthat/test-values.R

library(hipread)

context("Value conversions")

test_that("whitespace double to NA", {
  actual <- hipread_long(
    hipread_example("test-whitespace.dat"),
    hip_fwf_widths(
      c(1, 1, 1),
      c("rt", "var1", "var2"),
      c("character", "double", "double"),
      imp_dec = c(NA, 0, 1)
    )
  )

  expect_true(all(is.na(actual$var1)), "double no implicit decimal")
  expect_true(all(is.na(actual$var2)), "double one implicit decimal")
})

test_that("whitespace integer to NA", {
  actual <- hipread_long(
    hipread_example("test-whitespace.dat"),
    hip_fwf_widths(c(1, 2), c("rt", "var1"), c("c", "i"))
  )

  expect_true(all(is.na(actual$var1)), "integer")
})

Try the hipread package in your browser

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

hipread documentation built on Sept. 30, 2022, 5:08 p.m.