Skip to content

Suppressing Scientific Notation

2 messages · David Brahm, Brian Ripley

#
Big thanks to Prof Brian Ripley <ripley@stats.ox.ac.uk> and Martin Maechler
<maechler@stat.math.ethz.ch> for help in building a patch to allow suppression
of scientific notation!  The working patch is attached below.  Most helpfully,
BDR persuaded me to avoid mucking with the options.c code entirely, so I really
only needed to do three things:

 1) Add a component "scipen" to the R_print_par_t struct defined in Print.h,
 2) Set it via GetOption in PrintDefaults, using 0 if the option is undefined,
 3) Use it in format.c to penalize the character count for scientific notation.

Normally, R prints "1e+05" rather than "100000" because the former takes only 5
characters, while the latter takes 6, and 5 < 6.  Now if you set
  R> options(scipen=3)
R will penalize the scientific notation version by 3 characters, and will print
"100000" in this example because 5+3 >= 6.  ("scipen" = "scientific notation
penalty".)  Setting e.g. options(scipen=999) will prevent effectively all
scientific notation.

   Note I have not documented the new option, and I have not measured how much
of a performance hit it entails (though I hope the use of PrintDefaults keeps
that low).  Anyway, I submit this patch as a possible future enhancement of R.
#
I've merged this into R-devel, with some documentation.  I couldn't see
a measurable performance change.
On Mon, 5 May 2003, David Brahm wrote: