47

R is a statistics programming language. Part of R is the use of Packages, which themselves are written in the R language. Programming best practice includes the use of unit-testing to test the functions within these packages while they are being written and when they are used.

I am aware of a few packages for unit testing within R, these being

I'm interested to know;

Are there any other packages out there ? Given peoples experience, do these packages excel at different things ? What's the current state of the art in unit testing for R ?

Jon Seigel
  • 11,819
  • 8
  • 53
  • 90
PaulHurleyuk
  • 7,589
  • 14
  • 50
  • 75

2 Answers2

31

Unit testing seems to be more or less a solved problem, so all three packages will likely be adequate for your needs. There are subtle differences between them though:

RUnit is based on xunit, and as such is easy to understand if you've used any versions of it from other languages.

svUnit uses the same tests as RUnit, but includes a GUI to help with interactive use.

testthat isn't compatible with either, but includes much the same features and can check to only execute tests on files that haven't changed, which is useful for testing large projects.


Several years later...

RUnit and svUnit still don't have checks for messages and warnings, nor test caching, and don't seem to be under much development, so testthat should be your first choice for new projects. You can convert RUnit tests to testthat tests using my runittotestthat package.

Richie Cotton
  • 107,354
  • 40
  • 225
  • 343
  • 1
    `svUnit` can also provide output that is understood by the continuous integration tool [Hudson](https://hudson.dev.java.net/). – mariotomo Nov 19 '10 at 18:33
  • 1
    There is also now **[unitizer](https://github.com/brodieG/unitizer)**, though still in beta and github only (`devtools::install_github("brodieg/unitizer")`). It is fairly different to the existing frameworks as it stores test expressions and the resulting objects to allow easy regression checks. – BrodieG Jan 07 '15 at 19:36
6

here is a few things I've found from Google.

This topic was discussed on the mailing list here which mentioned the packages above. It seems RUnit and svunit will execute the same test code, but Runit also has tracking and code coverage functions.

A comparison of the two is also on the R wiki at http://rwiki.sciviews.org/doku.php?id=developers:runit

PaulHurleyuk
  • 7,589
  • 14
  • 50
  • 75
  • about the "code coverage" offered by RUnit, do check [this message](https://sourceforge.net/mailarchive/message.php?msg_name=474C639E.5080900%40epigenomics.com). it's from November 2007 but it still stands. – mariotomo Aug 24 '10 at 09:04
  • @mariotomo: that link no longer seems to work. Any comments or updates? – Iterator Aug 20 '11 at 16:42
  • better than a direct link, this is the way to find the message. it is in the `runit-help` mailing list of the `runit` project in sourceforge.net. it is by the author of `runit` and timestamped 2007-11-27 18:36. »Having said that please note that the inspect mechanism is not heavily used and tested as it is rather impractical as only one function call at a time can be tracked. This is far from being a code coverage tool.« – mariotomo Sep 01 '11 at 09:48