[Rd] Using unicode with sprintf or paste in Windows (PR#11515)

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon May 26 13:45:46 CEST 2008


Let me add that ?Encoding gives a pretty comprehensive description of how 
encodings are handled, including the circumstances in which they are 
preserved.

On Mon, 26 May 2008, ripley at stats.ox.ac.uk wrote:

> This is not a bug -- it is the expected (and documented) behaviour.
>
> On Mon, 26 May 2008, mwtoews at sfu.ca wrote:
>
>> Full_Name: Michael Toews
>> Version: 2.7.0
>> OS: Windows XP SP2
>> Submission from: (NULL) (24.80.163.230)
>>
>>
>> Using Unicode characters in Windows works with static strings (as of R 2.7.0),
>> however fails when used with sprintf() or paste(). For example, on R 2.7.0 for
>> Windows XP (SP2):
>>
>> Static string (works, showing Greek Delta character):
>>> print("\u0394Q = 2.2 L/s")
>> [1] "ΔQ = 2.2 L/s"
>>
>> However, when I use paste() or sprintf(), the Unicodeness is lost:
>>> paste("\u0394Q =",round(1.2345,3),"L/s")
>> [1] "<U+0394>Q = 1.234 L/s"
>>> sprintf("\u0394Q = %.3f L/s",1.2345)
>> [1] "<U+0394>Q = 1.234 L/s"
>>
>>
>> I have also tested this with R 2.7.0 for Linux, which yields the following:
>>> print("\u0394Q = 2.2 L/s")
>> [1] "&#916;Q = 2.2 L/s"
>>> paste("\u0394Q =",round(1.2345,3),"L/s")
>> [1] "&#916;Q = 1.234 L/s"
>>> sprintf("\u0394Q = %.3f L/s",1.2345)
>> [1] "&#916;Q = 1.234 L/s"
>
> It depends on the locale ... you cannot expect to be able to manipulate
> Unicode strings in a non-Unicode locale (although you can pass them around
> as data, unchanged).
>
>> (Note: this was posted on R-help with no replies:
>> https://stat.ethz.ch/pipermail/r-help/2008-May/162815.html )
>
> Well, the posting guide asks you to do your homework before posting.
> In this case, the 'R Internals' manual and the source code.
>
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list