From maechler at stat.math.ethz.ch  Thu May 12 11:18:13 2016
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 12 May 2016 11:18:13 +0200
Subject: [Rd] Too many spaces in deparsed complex numbers with
	digits17	control option
In-Reply-To: <CAPp_+=eeoQcYoN6a6GT9y3DXsTj_-sNPGJGMJvXbDB5EXqdjYw@mail.gmail.com>
References: <CAPp_+=eeoQcYoN6a6GT9y3DXsTj_-sNPGJGMJvXbDB5EXqdjYw@mail.gmail.com>
Message-ID: <22324.19029.303010.208850@stat.math.ethz.ch>

>>>>> Richard Cotton <richierocks at gmail.com>
>>>>>     on Thu, 5 May 2016 09:37:42 +0300 writes:

> 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

Thank you, Richie! 
I agree it should be improved ...
actually, there is even another improvement, so we don't get things like
  '2+-1i' but rather '2-1i'

(namely to use the '+' format modifier option for printf).

I have commited a change to R-devel (only, for now),
svn rev 70601 specifically.

Martin


--
Martin <Maechler at stat.math.ethz.ch>  http://stat.ethz.ch/people/maechler
Seminar f?r Statistik, ETH Z?rich  HG G 16      R?mistrasse 101
CH-8092 Zurich, SWITZERLAND
phone: +41-44-632-3408       fax: ...-1228      <><



[Rd] Too many spaces in deparsed complex numbers with digits17 control option
Martin Maechler