[R] (no subject)

Duncan Murdoch murdoch.duncan at gmail.com
Thu Apr 11 14:18:04 CEST 2013

On 13-04-11 7:56 AM, Kenn Konstabel wrote:
> Dear all,
> Is there a quick and easy way of converting utf characters to the \uxxxx
> form (necessary e.g. for packages)? I mean something working like this:
>> utf2uxxxx("õäöü")
> [1] "\u00f5\u00e4\u00f6\u00fc"
> It is easy to program but perhaps someone already has implemented this. (I
> couldn't find anything useful from searches incl RSiteSearch).

iconv() may be able to do it; the only caveat is that it is not part of 
R, and may vary from system to system.  On my Mac,

iconv("õäöü", to="C99")



so you'd get what you want with

cat('"', iconv("õäöü", to="C99"), '"', sep="")

However, on Windows, C99 is not a supported value for the destination 
encoding, so I think you'd have to program it via conversion to raw 
bytes.  Or maybe there's another function out there that I don't know about.

Duncan Murdoch

More information about the R-help mailing list