mwtoews at sfu.ca
2008-May-25 23:15 UTC
[Rd] Using unicode with sprintf or paste in Windows (PR#11515)
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] "ΔQ = 2.2 L/s"> paste("\u0394Q =",round(1.2345,3),"L/s")[1] "ΔQ = 1.234 L/s"> sprintf("\u0394Q = %.3f L/s",1.2345)[1] "ΔQ = 1.234 L/s" (Note: this was posted on R-help with no replies: https://stat.ethz.ch/pipermail/r-help/2008-May/162815.html )
ripley at stats.ox.ac.uk
2008-May-26 08:25 UTC
[Rd] Using unicode with sprintf or paste in Windows (PR#11515)
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] "ΔQ = 2.2 L/s" >> paste("\u0394Q =",round(1.2345,3),"L/s") > [1] "ΔQ = 1.234 L/s" >> sprintf("\u0394Q = %.3f L/s",1.2345) > [1] "Δ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
Maybe Matching Threads
- Feature request for 'sprintf' optimization (PR#9621)
- write.table does not quote col.names properly (PR#9044)
- Problem using R and Beamer...
- End of whiskers of boxplots are repeated on PDF device (PR#10499)
- CESA-2010:0394 Important CentOS 4 x86_64 kernel security, bug fix, and enhancement update