[Rd] Suppressing Scientific Notation

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon May 5 23:07:14 MEST 2003


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:

> Big thanks to Prof Brian Ripley <ripley at stats.ox.ac.uk> and Martin Maechler
> <maechler at 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.
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list