r - data.table and testthat package

后端 未结 1 1852
傲寒
傲寒 2021-01-12 11:31

I am building a package which works with data.table and which should be tested using package testthat. While the code works fine when calling from the command line, I run in

相关标签:
1条回答
  • 2021-01-12 12:12

    To long for comment so posting as answer.

    1. Don't use underscore in package name, it breaks the standard. Underscores will be turned to dots.

    2. Can't really tell you why testthat failed to process your test. You can try to export test function. It is not exported so should be used only with ::: explicitly. Maybe testthat depends on that in some way, don't know.

    3. Test is passing when I move tests out of testthat. If you fail to resolve it I would look for support in testthat issues.

    You can see my fork jangorecki/test_datatable_testthat of your pkg (url won't work in few days from now so fetch the changes if you want to access them later).
    Your test moved out of testthat is in tests/test.R, content below.

    dt <- test.datatable.testthat:::test()
    expected_res <- structure(list(TYPE = c("ERROR", "ERROR"),
                                   MESSAGE = c("Test","1234567890")),
                              row.names = c(NA, -2L), class = c("data.table","data.frame"),
                              .Names = c("TYPE", "MESSAGE"))
    stopifnot(all.equal(dt,expected_res))
    

    Testthat test is suppressed by changing it to dummy, kind of TRUE==TRUE. Now your test defined outside of testthat pass OK.
    Related part from 00check.log:

    * checking tests ...
      Running ‘test.R’
      Running ‘testthat.R’
     OK
    * DONE
    
    0 讨论(0)
提交回复
热议问题