[R] Obtain the hex code for a given character.

Rolf Turner r.turner at auckland.ac.nz
Wed Feb 5 01:57:20 CET 2014



If I have a character such as "£" stored in a object called "xxx", how 
can I obtain the hex code representation of this character?  In this 
case I know that the hex code is "\u00A3", but if I didn't, how would I 
find out?

I would like a function "foo()" such that foo(xxx) would return, say, 
the string "00A3".

I have googled and otherwise searched around and have come up with 
nothing that seemed at all helpful to me.  If I am missing something 
obvious, please point me at it.

(I have found a table on the web, which contains the information that I 
need, but it is only accessible "by eye" as far as I can discern.)

Supplementary question:  Suppose I have the string "00A3" stored in
an object called "yyy".  How do I put that string together with "\u"
so as to obtain "£"?  I thought I could do

	xxx <- paste("\u",yyy,sep="")

but R won't let me use "\u" "without hex digits".  How can I get around 
this?

Thanks.

cheers,

Rolf Turner



More information about the R-help mailing list