tests/testthat/test-freqs.R

library(hipread)

context("Read frequencies")

NVARS <- 8
HNUM_FREQ_SORTED <- c("003" = 2, "002" = 3, "001" = 4)
PERMIX_FREQ_SORTED <- c("x" = 1, "d" = 2, "1" = 3)

test_that("Can read a basic frequency example", {
  actual <- hipread_freqs(
    hipread_example("test-basic.dat"),
    list(
      H = hip_fwf_positions(
        start = c(1, 2, 5, 8, 11),
        end = c(1, 4, 7, 10, 12),
        col_names = c("rt", "hhnum", "hh_char", "hh_dbl", "hh_impdbl"),
        col_types = "character"
      ),
      P = hip_fwf_positions(
        start = c(1, 2, 5, 6, 9),
        end = c(1, 4, 5, 8, 9),
        col_names = c("rt", "hhnum", "pernum", "per_dbl", "per_mix"),
        col_types = "character"
      )
    ),
    hip_rt(1, 1)
  )

  expect_equal(length(actual), NVARS)
  expect_equal(sort(actual$hhnum), HNUM_FREQ_SORTED)
  expect_equal(sort(actual$per_mix), PERMIX_FREQ_SORTED)
})

Try the hipread package in your browser

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

hipread documentation built on May 29, 2024, 1:50 a.m.