[Rd] Suppressing Scientific Notation
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri May 2 18:07:50 MEST 2003
A couple of hints:
1) You don't need to touch the internal code for options: you can just
set options(scipen=100), or rely on it being unset for the default.
2) I would do something like
R_print.scipen = asInteger(GetOption(install("scipen"), rho));
if(R_print.scipen == NA_INTEGER) R_print.scipen = 0;
Your way you need GetOptionSciPen defined in some common header.
I believe (but have not checked) that if options("scipen") is not defined
then GetOption(install("scipen"), rho) will be NULL and asInteger(NULL)
will be NA_INTEGER, but it might well be worth being more cautious.
On Fri, 2 May 2003, David Brahm wrote:
> R gurus,
>
> Every so often(*) someone asks how to suppress scientific notation in
> printing, so I thought I'd give it a shot, but I need some help.
>
> The formatting decision is made(**) on line 286 of src/main/format.c :
>
> if (mF <= *m) { /* IFF it needs less space : "F" (Fixpoint) format */
>
> where mF is the number of characters for "normal" printing and *m is the number
> of characters for scientific notation. If mf <= *m, then parameters are set
> that cause "normal" printing. My idea was to introduce a "penalty" for
> scientific notation, which changes line 286 to:
>
> if (mF <= *m + R_print.scipen) {
>
> R_print.scipen is an integer (defaulting to 0) set with "options":
> R> options(scipen=99)
>
> I tried to copy the code for R_print.digits (as in "options(digits=7)")
> wherever I found it, notably in the struct "R_print_par_t" defined in Print.h.
> I changed main/options.c and main/print.c, as detailed in the diff output
> below. But I must have done it wrong because my version of R crashes with:
> > Error: bad value
> > Segmentation fault
>
> Can anyone more familiar with options() help? How do you add a new option
> parameter? Thanks!
>
--
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