Re: [Rd] Flag '#' in sprintf() format string "%#x"?

From: Marc Schwartz <marc_schwartz_at_me.com>
Date: Sat, 20 Jun 2009 18:27:45 -0500

On Jun 20, 2009, at 5:44 PM, Henrik Bengtsson wrote:

> Hi, this is a bit of FYI, but also a question.
>
> Is flag '#' in sprintf() format string "%#x" fully supported across
> platforms? Can that be assumed? I discovered thanks to the r-forge
> service, that this was not the case for OSX with "R version 2.9.0
> Under development (unstable) (2009-01-13 r47593)", where R CMD check
> reports the following:
>
> Error in sprintf("%#x", values) :
> use format %d, %i, %x or %X for integer objects
>
> where values <- as.integer(1:5). Note it works well on other
> platforms; I don't know about newer R version on OSX. Should I
> consider this a glitch in an old version of R (newer R version do a
> much better validation here), or should I simply avoid '#'?
>
> Thanks,
>
> /Henrik

Henrik,

ink1">ink2">Using:

R version 2.9.0 Patched (2009-06-05 r48712)

on a fully updated OSX 10.5.7 MacBook Pro:

values <- 1:5

 > sprintf("%#x", values)
[1] "0x1" "0x2" "0x3" "0x4" "0x5"

Note that the as.integer() is not needed, as ':' will return integers if both from and to values are integers:

 > str(values)
  int [1:5] 1 2 3 4 5

The only comment that I see in NEWS that may be relevant here for 2.9.0 is:

     o	sprintf() does stricter error checking on input formats to
	avoid passing invalid formats to the OS (which have a tendency
	to crash under such inputs).


HTH, Marc Schwartz



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 20 Jun 2009 - 23:32:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 21 Jun 2009 - 17:31:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive