[Rd] Too many spaces in deparsed complex numbers with digits17 control option
Richard Cotton
richierocks at gmail.com
Thu May 5 08:37:42 CEST 2016
If you set the "digits17" control option in deparse, you get a lot of
unnecessary space in the representation of complex numbers.
> deparse(0 + 0i)
[1] "0+0i"
> deparse(0 + 0i, control = "digits17")
[1] "0 + 0i"
As far as I can tell, the logic for this comes from this piece of
/src/main/deparse.c:
if (TYPEOF(vector) == CPLXSXP && (d->opts & DIGITS16)) {
Rcomplex z = COMPLEX(vector)[i];
if (R_FINITE(z.r) && R_FINITE(z.i)) {
snprintf(hex, 64, "%.17g + %17gi", z.r, z.i);
strp = hex;
} else
strp = EncodeElement(vector, i, quote, '.');
}
I think this is a small bug, and that "%17gi" in the snprintf call
ought to be "%.17gi".
Also there shouldn't be any space around the plus sign for consistency
with the non-digits17 option.
Is this a real bug, or is it deliberate behaviour?
--
Regards,
Richie
Learning R
4dpiecharts.com
More information about the R-devel
mailing list