[Rd] format bug and patch
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Aug 17 07:32:35 CEST 2013
On 16/08/2013 20:47, Aleksey Vorona wrote:
> On 8/16/13, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>> On 13-08-15 6:07 PM, Aleksey Vorona wrote:
>>> Dear R-team,
>>> I've been using R for a while and decided to contribute some bug
>>> fixes. The first bug I tried to solve was
>>> I have attached a patch with the fix to the bug and would love to hear
>>> comments about its quality.
>>> Also, while testing this bug I found another related issue:
>>>> format(complex(real=10, imaginary=4), digits = 1);
>>>  "10+0i"
>>> I think this should've been "10+4i". I have entered this as a bug
>>> #15427. But a patch for formatComplex() would be a bigger change, than
>>> the patch for formatReal() I made. So, before I start, I would like to
>>> gauge your opinion.
>>> Do you agree it is a bug?
>> No, it is a somewhat questionable design, but not a bug. You asked for
>> 1 significant digit. format() will give both the real and imaginary
>> parts accurate to 1 significant digit. Since the real part has two
>> digits, it handles the imaginary part as 04, which is rendered as 0.
>> The questionable part of the design is that 11+4i would be rendered as
>> 11+0i, i.e. two digits accuracy are given in the real part even though
>> you only asked for one. I think it would be better to be consistent
>> here. I think it makes more sense to give 11+4i (or 10+4i in your
>> example) than to give 10+0i for both, but I think that is a matter of
>> taste, rather than a bug fix.
>> I have also prepared a patch for the 15411 bug; I'll compare mine to
>> yours and commit something, but not for a week or so: I am mostly
>> offline until then.
>> Duncan Murdoch
> Thank you for the reply. I sent this message to Duncan only.
> Re-sending this again to the list. Sorry...
> My interpretation of digits=1 was that I want both real and imaginary
> parts to have 1 significant digits.
> Consider this command, no digits parameter this time:
>> format(complex(real=5.6e+8, imaginary=2.1e+16));
>  "0e+00+2.1e+16i"
> I do not see a reason not to output the number as it was entered.
> If it is not a bug, it should be documented. I'll check if I can help with that.
It is documented. You can help by reading the documentation for yourself!
digits: how many significant digits are to be used for numeric and
complex ‘x’. The default, ‘NULL’, uses
‘getOption("digits")’. This is a suggestion: enough decimal
places will be used so that the smallest (in magnitude)
number has this many significant digits, and also to satisfy
‘nsmall’. (For the interpretation for complex numbers see
For ‘signif’ the recognized values of ‘digits’ are ‘1...22’, and
non-missing values are rounded to the nearest integer in that
range. Complex numbers are rounded to retain the specified number
of digits in the larger of the components.
> -- Aleksey
> R-devel at r-project.org mailing list
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