From gb at stat.umu.se  Sun Jun 21 10:33:13 2009
From: gb at stat.umu.se (=?ISO-8859-1?Q?G=F6ran_Brostr=F6m?=)
Date: Sun, 21 Jun 2009 10:33:13 +0200
Subject: [Rd] Flag '#' in sprintf() format string "%#x"?
In-Reply-To: <B307D518-77C8-4A5C-9378-6986B82B3B0E@me.com>
References: <59d7961d0906201544x184e2d4ehd2da3cf66603a3@mail.gmail.com>
	<B307D518-77C8-4A5C-9378-6986B82B3B0E@me.com>
Message-ID: <4A3DF049.7030209@stat.umu.se>



Marc Schwartz wrote:
> 
> 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,
> 
> 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:

That is obviously true, but

 > is.integer(1)
 > FALSE


 > is.integer(1:5)
 > TRUE

and, surprisingly,

 > is.integer(1.0:5.2)
 > TRUE

Documentation of ":" says, about 'Value':

"For numeric arguments, a numeric vector.  This will be of type
      'integer' if 'from' and 'to' are both integers and representable
      in the integer type, otherwise of type 'numeric'.

This is true, but not the full truth. Instead it should read

"...This will be of type 'integer' if 'from' is representable in the 
integer type, otherwise of type 'double'"

G?ran
-- 
G?ran Brostr?m               phone: 46 90 786 5223; 46 705 197 507
Department of Statistics     fax: 46 90 786 6614
Ume? University              email: gb at stat.umu.se
SE-90187 Ume?, Sweden        http://tal.stat.umu.se/~gb



[Rd] Flag '#' in sprintf() format string "%#x"?
=?ISO-8859-1?Q?G=F6ran_Brostr=F6m?=