9

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?

David LeBauer
  • 31,011
  • 31
  • 115
  • 189

1 Answers1

3

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • There is a set R functions that call C functions, and I can test these from R. However, there are also C functions that are never called from R, and we are producing more of these as we re-factor, but it really isn't a stand-alone library. – David LeBauer May 27 '13 at 20:11
  • I infer that writing R wrappers to C functions is greatly simplified using Rcpp, based on the [Rcpp package description](http://cran.r-project.org/web/packages/Rcpp/index.html) that states "a framework that allows exposing C++ functions and classes to the R level". Perhaps the approach I have inherited suboptimal, but we pass lots of lists of varied-type parameters. – David LeBauer May 27 '13 at 20:20
  • If you read up on Rcpp (particularly what we call _Rcpp attributes_) you will see that wrapping C (and C++) functions is now trivial and fully automated. – Dirk Eddelbuettel May 27 '13 at 20:55