tests/testthat/test_get_this.R

# get_this
library(manymodelr)
test_that(desc="test get_this",
                    code={
                      skip_on_oldrel()
            expect_equal(ceiling(get_this(yields,"yield")[1, ]),
                         521)
            # expect that unnamed lists throw an error as required
            unnamed_list <- list(1:5,1:4)
              expect_error(get_this(yields,
                                    "non_existent"),
        "what should be a valid name in where. Perhaps you have an unnamed list?",
                                     fixed=TRUE)  
              
              expect_equal(get_this(unnamed_list,2)[[1]][2],2)
              expect_error(get_this(unnamed_list),
                           "Both what and where are required", fixed=TRUE)
              named_list <- list(A=1:4,B=7:10)
              expect_equal(get_this(named_list, "A")[[1]][3],3)
              expect_true(is.data.frame(get_this(yields,"normal")))
              
              test_nested =list(A=list(A=1:3),B=list(B=1:4))
             expect_error(get_this(test_nested,what="C"),
        "what should be a valid name in where. Perhaps you have an unnamed list?",
                          fixed = TRUE)
            expect_equal(length(get_this(test_nested,"A")[[1]]),3)
             
              })

Try the manymodelr package in your browser

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

manymodelr documentation built on Nov. 15, 2021, 5:07 p.m.