[R-pkg-devel] test script output

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Fri Jan 31 18:23:54 CET 2025


>>>>> Kevin R Coombes 
>>>>>     on Fri, 31 Jan 2025 11:48:33 -0500 writes:

    > Hi,

    > I have a package that has been in CRAN for years and is now failing 
    > checks because some of the output of a test script is differing on some 
    > machines in the fifth or sixth decimal place. I have managed to fix most 
    > of these issues (by using the "digits" argument in calls to "summary" to 
    > hide the differences). the only one that remains yields this R CMD check 
    > report:

    > Comparing ‘testDiff.Rout’ to ‘testDiff.Rout.save’ ...52c52
    > < 2.600e-06 1.328e-01 4.666e-01 1.060e+00 1.369e+00 1.091e+01
    > ---
    > > 0.000003  0.132800  0.466600  1.060000  1.369000 10.910000 

    > Here the digit-limited output is the same (to a human mathematician, though not to a string-matching computer), but one machine has decided to report the output in scientific notation.

I'm guessing you are slightly off here:
Almost surely it's *not* a difference in machine/platform but only in versions
of R-devel.

My guess comes from the fact that I've been the R core member
who committed this change to R-devel :
  ------------------------------------------------------------------------
  r87625 | maechler | 2025-01-24 16:58:25 +0100 (Fri, 24 Jan 2025)

  parametrize & improve accuracy in print(summary(<numbers>))
  ------------------------------------------------------------------------

a week ago.
... and BTW, if you look carefully, for the first entry, the new
output *is* slightly more accurate also in your example.

I agree that the switch from fixed point to
exponential/scientific format is "unlucky" in this case
[and even unnecessary: in this case, keeping fixed format and
 showing one digit more (using the same amount of characters),
 one could also have shown the 0.0000026 ...]

A workaround for you may be to set something like

   options(scipen = 2) # default is 0

in your testDiff.R  script  before printing

All this is only in R-devel, the development version of R...
and I have contemplated to add more tweaks to
print.summaryDefault()  for that upcoming version of R.

The fear stopping me to do more tweaking was that the
consequence could be even *more* (still small) changes in such
summary() printing output.

    >  Both versions were produced by a command equivalent to
    > print(summary(x, digits = 4))

As you may (or may not ..;-) guess from the above commit message ("parametrize")
is that  print(summary(<numbers>)) got a new argument zdigits.

So, instead of     print(summary(x, digits = 4))
you can, from R version 4.5 (currently only in the development
version of R) on use

    print(summary(x, digits = 4), digits = .., zdigits = ..)

but you could also --- already in current versions of R ---
tweak the output using

    print(summary(x, digits = 4), digits = <n>)

where you can play to see if  n=3 , n=4, or n=5
help you getting better results ..
... actually *not* 'digits = 4'  for summary() at all,
but only the digits argument to print(.)   {where you'll get a
the new 'zdigits' argument *additionally* in R-devel and future
R version's}.


    > What is the best cross-platform way to ensure that the output gets printed in the same format? Set "options(scipen=999)"? 

That's clearly too extreme to generally,
(I mentioned `scipen = 2` earlier).

> Alternatively, pass some argument to "print" as well as to  "summary"?

yes, see above.

> (The other alternative I am considering is to just delete the script from the "tests" directory.)

(I don't think that would be a good idea, .. but rather a very b.. one)


    > Thanks,
    > Kevin
Best,
Martin



More information about the R-package-devel mailing list