tests/testthat/test_splitlevel.R

test_that('splitlevel makes a new factor with split level',{

        ## Success test
        x <- data.frame(first = c(1:20), second = rep(c("A","B"), each = 10),
                        third = rep_len(c("W","X","Y","Z"), 20))
        res <- splitlevel(x,"second","A","third", "callitwhatyouwant")

        expect_identical( TRUE , all(res["callitwhatyouwant"] ==
                                c("A_W","A_X","A_Y",
                                "A_Z","A_W","A_X","A_Y",
                                "A_Z","A_W","A_X","B","B","B","B","B","B",
                                "B","B","B","B")))
        ## Failure test
        expect_error(splitlevel(x,"second","A","third", x),
                     'The input "newfactorname" is not of the class character!')
})
KPdir/foofactors documentation built on May 8, 2019, 4:41 p.m.