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?
Asked
Active
Viewed 356 times
1
-
1Your 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 Answers
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()
-
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