[Rd] Flag '#' in sprintf() gives an error in R v2.9.0 devel

Henrik Bengtsson hb at stat.berkeley.edu
Mon Feb 2 20:34:37 CET 2009


Hi,

in R v2.8.1 patched (2008-12-22 r47296) the following works:

> sprintf("%#x", 1)
[1] "0x1"

whereas in R v2.9.0 devel (2009-01-08 r47515) it gives:

> sprintf("%#x", 1);
Error in sprintf("%#x", 1) :
  use format %f, %e, %g or %a for numeric objects

Not sure if this was an intended move or not.

DETAILS:
Typically, the '#' flag modifies the output of (s)printf() as follows:

"#  Used with o, x or X specifiers the value is preceeded with 0, 0x
or 0X respectively for values different than zero.
Used with e, E and f, it forces the written output to contain a
decimal point even if no digits would follow. By default, if no digits
follow, no decimal point is written. Used with g or G the result is
the same as with e or E but trailing zeros are not removed."

Source: http://www.cplusplus.com/reference/clibrary/cstdio/printf.html

I know there are many flavors of what format strings printf() supports
and I don't have the Kernighan & Ritchie book in help(sprintf).

/Henrik



More information about the R-devel mailing list