[Rd] R vs. C

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Jan 17 20:16:31 CET 2011

On Mon, Jan 17, 2011 at 6:57 PM, David Henderson <dnadavewa at yahoo.com> wrote:
> I think we're also forgetting something, namely testing.  If you write your
> routine in C, you have placed additional burden upon yourself to test your C
> code through unit tests, etc.  If you write your code in R, you still need the
> unit tests, but you can rely on the well tested nature of R to allow you to
> reduce the number of tests of your algorithm.  I routinely tell people at Sage
> Bionetworks where I am working now that your new C code needs to experience at
> least one order of magnitude increase in performance to warrant the effort of
> moving from R to C.
> But, then again, I am working with scientists who are not primarily, or even
> secondarily, coders...

If you write your code in C but interface to it in R, you can use the
same R test harness system. I recently coded something up in R, tested
it on small data, discovered it was waaay too slow on the real data,
rewrote the likelihood calculation in C, and then used the same test
set to make sure it was giving the same answers as the R code. It
wasn't. So I fixed that bug until it was. If I'd written the thing in
C to start with I might not have spotted it.

 Sometimes writing a prototype in R is a useful testing tool even when
you know it'll be too slow - as an interpreted language R gives you a
rapid development cycle and handy interactive debugging possibilities.
Things that do exist in C but require compilation....


More information about the R-devel mailing list