Nautica
Nautica

Reputation: 2018

How do you print unicode symbols in a kable/formattable table?

A basic R code chunk to display the problem in an RMarkdown script:

library(formattable)

df <- data.frame(test = c("\u2265", "\u2264", "==", "equals", "!=", "\u2265=", "\u2264="))

formattable(df)

Doesn't show any of the unicode symbols after I try and knit to html, instead replacing them with =:

enter image description here

Upvotes: 3

Views: 1242

Answers (1)

Dan
Dan

Reputation: 12084

If you write your unicode characters in html format (i.e., replace \u with &#x and tag ; on the back end), then they appear correctly.

library(formattable)

df <- data.frame(test = c("&#x2265;", "&#x2264;", "==", "equals", 
                          "!=", "&#x2265;=", "&#x2264;="))

format_table(df)

enter image description here

Upvotes: 4

Related Questions