tests/testthat/test_recode.R

library(bbw)
context("Recode")

var <- 1:5
recodes <- "1:2=1;3:4=2;else=NA"
x <- recode(var = var, recodes = recodes)

test_that("x is numeric", {
  expect_is(x, "numeric")
})

test_that("recode is c(1, 1, 2, 2, NA)", {
  expect_equal(x[1], 1)
  expect_equal(x[2], 1)
  expect_equal(x[3], 2)
  expect_equal(x[4], 2)
  expect_true(is.na(x[5]))
})

var <- letters[1:5]
recodes <- "'a'=1;'b'=2;else=NA"
x <- recode(var = var, recodes = recodes)

test_that("x is numeric", {
  expect_is(x, "numeric")
})

test_that("recode is c(1, 2, NA, NA, NA)", {
  expect_equal(x[1], 1)
  expect_equal(x[2], 2)
  expect_true(is.na(x[3]))
  expect_true(is.na(x[4]))
  expect_true(is.na(x[5]))
})

Try the bbw package in your browser

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

bbw documentation built on May 30, 2022, 9:10 a.m.