tests/testthat/test-fac2num.R

context("fac2num")

test_that("fac2num works", {

    x <- c(3, 4, 9, 4, 9)
    xf <- factor(x, levels=unique(x))
    expect_equal(fac2num(xf), x)

    names(x) <- sample(LETTERS, length(x))
    xf <- factor(x, levels=unique(x))
    expect_equal(fac2num(xf), x)

    z <- c(994.18, 1-1e-6, -25.1, Inf, NA, 1-1e-6)
    zf <- factor(z)
    expect_equal(fac2num(zf), z)

})

Try the broman package in your browser

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

broman documentation built on July 8, 2022, 5:07 p.m.