This sounds like a simple question but I cannot solve it somehow. I want to print, preferably with the knitr::kable() function, a data frame that contains a string with a 'greater than or equal sign' (or the opposite one) in R, but the sign is converted to an 'equal (=)' sign when printed. I will show you the problem first, and then what I already did to try to find the answer.
library(knitr)
minimal.example <- data.frame(x= "≥10",y="≤20")
# note: same results with data.frame(x="\U2265 10", y="\U2264 20")
knitr::kable(minimal.example)
output:
| x | y |
|---|---|
| =10 | =20 |
Expected output:
| x | y |
|---|---|
| ≥10 | ≤20 |
I know from the answers here and here that this problem occurs in plain R as well as in Rstudio, and only in R installed under Windows; thus it is not reproducible on MAC or Linux operating systems. A suggestion made here using the expression() function does not work in my case, probably because of my windows machine? The problem also occurs with the base R print function print(minimal.example) so it is not restricted to the kable() function.
I've updated my R version to the latest one but have still the same result. I've also tried a different locale (Dutch_Netherlands.1252) and someone else tried a US locale without effect.
Two questions:
- Can someone explain what is going on? (my guess is that it happens in the base R
data.framefunction?) - How can I solve this problem to get the desired result? I need to be able to convert it to both latex and html within an Rmarkdown document (usually no problem with the kable function).
Any help is greatly appreciated!
Session info:
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.30
loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3 highr_0.8 xfun_0.19