Unit tests for code in the /src folder of an R package?

柔情痞子 提交于 2019-12-05 22:45:50

问题


I am contributing to an R package that makes extensive use of C code for computation.

We have started writing tests for R functions using the testthat package, placing the tests in inst/tests following instructions here.

Is the testthat package appropriate for testing C functions directly (e.g. those without R interfaces)? Or do we find a separate C testing package? If so, 1) where should these tests go, 2) how do I get them to run during R CMD check, and 3) is any C testing package particularly appropriate in this context?


回答1:


I find the question a little confused:

  • Either you consider your C code to be in support of higher-level R functions that you can test at the R (as you seem to have done)

  • Or you consider your C code to be more standalone, in which case you could use one of a bazillion unit testing frameworks for C.

Many of the packages using Rcpp also use extensive unit testing, either via RUnit, or via testthat. You could look at that. I generally test at the R function level, which often implies a test of the underlying C++ function.



来源:https://stackoverflow.com/questions/16779583/unit-tests-for-code-in-the-src-folder-of-an-r-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!