5

In R, you can specify unicode characters by using \u and then a code.

"\u00c3"
[1] "Ã"

What if I already have the "00c3" part as a string, how can I get the unicode?


string <- "00c3"

paste0("\u", string)
#> Error: '\u' used without hex digits in character string starting ""\u"

paste0("\\u", string)
#> [1] "\\u00c3"

eval(paste0("\\u", string))
#> [1] "\\u00c3"

I know about the function rawToChar(), but the raw version of this character is c3 82. How can I get that from 00c3?

GregF
  • 1,292
  • 11
  • 14

1 Answers1

7
library(stringi)
stri_unescape_unicode(paste0("\\u","00c3"))
#[1] "Ã"

You may also want to check out this function.

d.b
  • 32,245
  • 6
  • 36
  • 77
  • 1
    Oh, thanks, I knew there must be a way with `parse()`, but couldn't figure it out. (I see that that's not the point of that answer, but it was bothering me that I couldn't figure it out) – GregF Aug 10 '17 at 17:32