1

I have utf8 encoded text that R seems to be representing as ascii. Here is the simplest case in the R console. Is there a way to force R to encode the characters in utf8?

Running in R console

Jim G.
  • 15,141
  • 22
  • 103
  • 166
Old Man
  • 3,295
  • 5
  • 23
  • 22
  • 1
    Your data is UTF-8, but Rstudio is _printing_ it using ASCII – Hong Ooi Oct 29 '19 at 11:25
  • How do I force it to print using utf-8? For example, I'm using GT to render this data as tables, I it prints all these angle brackets. – Old Man Oct 29 '19 at 11:45
  • What OS are you using? Is this an R notebook because that doesn't look like the R console. If so, what attributes do you have in the header? What does `sapply(data, Encoding)` return? – MrFlick Oct 29 '19 at 14:44
  • It is an R notebook on Windows. sapply returns "UTF-8" – Old Man Oct 30 '19 at 08:54

1 Answers1

1

Have you tried to use knitr or DT libraries to output your table ? It worked for me.

E.g. :

tribble(
  ~x,  ~y, ~ z,
  "a", 1:3, "校",
  "♫", 4:6, 5
) %>% 
  knitr::kable()

tribble(
  ~x,  ~y, ~ z,
  "a", 1:3, "校",
  "♫", 4:6, 5
) %>% 
  DT::datatable()
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
cyrilb38
  • 924
  • 6
  • 17
  • Those work for me too. Apparently R understands the text to be UTF-8, it just doesn't display it that way. – Old Man Oct 30 '19 at 09:11