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). Thanks in advance, Kenn -- P.S. Apologies if this is double posted - there was a network error and the first message doesn't seem to have been sent out (but maybe it was). Kenn Konstabel Department of Chronic Diseases National Institute for Health Development Hiiu 42 Tallinn, Estonia [[alternative HTML version deleted]]
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") gives "\\u00f5\\u00e4\\u00f6\\u00fc" 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
HI, May be this helps: library(Unicode) utf2uxxx<- function(x){ ?a<- tolower(as.u_char(utf8ToInt(x))) ?a<- gsub("[+]","",a) ?a<- paste(paste("\\",a,sep=""),collapse="") ?a<-cat('"',a,'"',sep="")} utf2uxxx("????") #"\u00f5\u00e4\u00f6\u00fc" sessionInfo() R version 3.0.0 (2013-04-03) Platform: x86_64-unknown-linux-gnu (64-bit) A.K. ----- Original Message ----- From: Kenn Konstabel <lebatsnok at gmail.com> To: R-help <r-help at stat.math.ethz.ch> Cc: Sent: Thursday, April 11, 2013 7:56 AM Subject: [R] (no subject) 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). Thanks in advance, Kenn -- P.S.? Apologies if this is double posted - there was a network error and the first message doesn't seem to have been sent out (but maybe it was). Kenn Konstabel Department of Chronic Diseases National Institute for Health Development Hiiu 42 Tallinn, Estonia ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.