Skip to content
Prev 47914 / 63424 Next

NOTE when detecting mismatch in output, and codes for NOTEs, WARNINGs and ERRORs

On 03/26/2014 04:58 AM, Kirill M?ller wrote:
The problem is that differences occur too often because this is a 
comparison of characters in the output files (a diff). Any output that 
is affected by locale, node name or Internet downloads, time, host, or 
OS, is likely to cause a difference. Also, if you print results to a 
high precision you will get differences on different systems, depending 
on OS, 32 vs 64 bit, numerical libraries, etc.  A better test strategy 
when it is numerical results that you want to compare is to do a 
numerical comparison and throw an error if the result is not good, 
something like

   r <- result from your function
   rGood <- known good value
   fuzz <- 1e-12  #tolerance

   if (fuzz < max(abs(r - rGood))) stop('Test xxx failed.')

It is more work to set up, but the maintenance will be less, especially 
when you consider that your tests need to run on different OSes on CRAN.

You can also use try() and catch error codes if you want to check those.

Paul