[Rd] Suppressing Scientific Notation
Martin Maechler
maechler at stat.math.ethz.ch
Fri May 2 20:50:51 MEST 2003
>>>>> "BDR" == Prof Brian Ripley <ripley at stats.ox.ac.uk>
>>>>> on Fri, 2 May 2003 17:07:50 +0100 (BST) writes:
BDR> A couple of hints:
BDR> 1) You don't need to touch the internal code for options: you can just
BDR> set options(scipen=100), or rely on it being unset for the default.
BDR> 2) I would do something like
BDR> R_print.scipen = asInteger(GetOption(install("scipen"), rho));
BDR> if(R_print.scipen == NA_INTEGER) R_print.scipen = 0;
BDR> Your way you need GetOptionSciPen defined in some
BDR> common header.
I remember vaguely that the more tedious way we do for the
"digits" leads to quite substantial speed improvements as
opposed to always have to go through GetOption(install("..."), rho).
Printing of "numeric" data is such a basic thing that it should
be as fast as possible. I said *vaguely* though ...
In any case, David, I think it's quite a neat idea to provide
such an option. I've also had such requests which didn't go to
the mailing lists..
Martin
BDR> I believe (but have not checked) that if
BDR> options("scipen") is not defined then
BDR> GetOption(install("scipen"), rho) will be NULL and
BDR> asInteger(NULL) will be NA_INTEGER, but it might well
BDR> be worth being more cautious.
BDR> 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!
>>
BDR> --
BDR> Brian D. Ripley, ripley at stats.ox.ac.uk
BDR> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
BDR> University of Oxford, Tel: +44 1865 272861 (self)
BDR> 1 South Parks Road, +44 1865 272866 (PA)
BDR> Oxford OX1 3TG, UK Fax: +44 1865 272595
BDR> ______________________________________________
BDR> R-devel at stat.math.ethz.ch mailing list
BDR> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list