Unicode characters '≥' and '≤' are getting replaced by '='

Hi everyone,

I am not sure if this is the best place for this, but I really hope someone can help me in the right direction to solve this. I have a problem with the display of unicode characters '≥' and '≤' in the output: R changes these characters to a '=' sign. I happens under windows but not under linux.

I came across this problem after reading an excel file with readxl::readr(), but the following minimal reproducible example gives the same error:

a <- data.frame(x= "≥",y="≤")
a

Output:
x y
= =

Expected output:
x y
≥ ≤

Session info:
R version 4.0.2 (2020-06-22) (EDIT: same happens after updating to R 4.0.3)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Rstudio version 1.4.1087
LC_COLLATE=English_United Kingdom.1252

Same happens on a different computer with the same R version (4.0.2) but with a different locale:
LC_COLLATE=Dutch_Netherlands.1252

But it does not happen on a Linux server with an older R version:
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Cloud Infrastructure
LC_CTYPE=en_US.UTF-8

In the last Linux environment I get the expected result, but I also need it to work on my personal computer.
Is this because of the R version? Or because the locale is not set properly? Or it just does not work under windows? Any help is appreciated!

Some follow-up information: when using a tibble instead of a data frame, printing the tibble works as expected when I use the unicode name:

minimal.example.data <- tidyr::tribble(
  ~var1, ~var2,
  "\U2265", "\U2264"
)
minimal.example.data 

Correct output:
A tibble: 1 x 2

var1 var2

However, as soon as I convert this to a kable for more table displaying options, it converts the signs to an 'equal to' sign again:

knitr::kable(minimal.example.data)

output:

var1 var2
= =

I can't reproduce this.

library(tidyverse)

minimal.example.data <- tidyr::tribble(
  ~var1, ~var2,
  "\U2265", "\U2264"
)
minimal.example.data 
#> # A tibble: 1 x 2
#>   var1  var2 
#>   <chr> <chr>
#> 1 ≥     ≤

knitr::kable(minimal.example.data)
var1 var2

Created on 2021-01-18 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       macOS High Sierra 10.13.6   
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2021-01-18                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.0)
#>  backports     1.1.7   2020-05-13 [1] CRAN (R 4.0.0)
#>  blob          1.2.1   2020-01-20 [1] CRAN (R 4.0.2)
#>  broom         0.7.0   2020-07-09 [1] CRAN (R 4.0.2)
#>  callr         3.4.3   2020-03-28 [1] CRAN (R 4.0.0)
#>  cellranger    1.1.0   2016-07-27 [1] CRAN (R 4.0.0)
#>  cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.0)
#>  colorspace    1.4-1   2019-03-18 [1] CRAN (R 4.0.0)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.0)
#>  DBI           1.1.0   2019-12-15 [1] CRAN (R 4.0.0)
#>  dbplyr        1.4.4   2020-05-27 [1] CRAN (R 4.0.2)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.0)
#>  devtools      2.3.1   2020-07-21 [1] CRAN (R 4.0.2)
#>  digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.0)
#>  dplyr       * 1.0.0   2020-05-29 [1] CRAN (R 4.0.2)
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.0)
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.0)
#>  forcats     * 0.5.0   2020-03-01 [1] CRAN (R 4.0.0)
#>  fs            1.4.1   2020-04-04 [1] CRAN (R 4.0.0)
#>  generics      0.0.2   2018-11-29 [1] CRAN (R 4.0.0)
#>  ggplot2     * 3.3.2   2020-06-19 [1] CRAN (R 4.0.2)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  gtable        0.3.0   2019-03-25 [1] CRAN (R 4.0.0)
#>  haven         2.3.1   2020-06-01 [1] CRAN (R 4.0.2)
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.0)
#>  hms           0.5.3   2020-01-08 [1] CRAN (R 4.0.0)
#>  htmltools     0.4.0   2019-10-04 [1] CRAN (R 4.0.0)
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.0.2)
#>  jsonlite      1.7.0   2020-06-25 [1] CRAN (R 4.0.2)
#>  knitr         1.29    2020-06-23 [1] CRAN (R 4.0.2)
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.0)
#>  lubridate     1.7.9   2020-06-08 [1] CRAN (R 4.0.2)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.0)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.2)
#>  modelr        0.1.8   2020-05-19 [1] CRAN (R 4.0.2)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.0.0)
#>  pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.2)
#>  pkgbuild      1.0.8   2020-05-07 [1] CRAN (R 4.0.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.0)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 4.0.0)
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.0)
#>  processx      3.4.2   2020-02-09 [1] CRAN (R 4.0.0)
#>  ps            1.3.3   2020-05-08 [1] CRAN (R 4.0.0)
#>  purrr       * 0.3.4   2020-04-17 [1] CRAN (R 4.0.0)
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.0)
#>  Rcpp          1.0.5   2020-07-06 [1] CRAN (R 4.0.2)
#>  readr       * 1.3.1   2018-12-21 [1] CRAN (R 4.0.0)
#>  readxl        1.3.1   2019-03-13 [1] CRAN (R 4.0.0)
#>  remotes       2.2.0   2020-07-21 [1] CRAN (R 4.0.2)
#>  reprex        0.3.0   2019-05-16 [1] CRAN (R 4.0.0)
#>  rlang         0.4.7   2020-07-09 [1] CRAN (R 4.0.2)
#>  rmarkdown     2.1     2020-01-20 [1] CRAN (R 4.0.0)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 4.0.0)
#>  rvest         0.3.5   2019-11-08 [1] CRAN (R 4.0.0)
#>  scales        1.1.1   2020-05-11 [1] CRAN (R 4.0.0)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
#>  stringi       1.4.6   2020-02-17 [1] CRAN (R 4.0.0)
#>  stringr     * 1.4.0   2019-02-10 [1] CRAN (R 4.0.0)
#>  testthat      2.3.2   2020-03-02 [1] CRAN (R 4.0.2)
#>  tibble      * 3.0.3   2020-07-10 [1] CRAN (R 4.0.2)
#>  tidyr       * 1.1.0   2020-05-20 [1] CRAN (R 4.0.2)
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.0)
#>  tidyverse   * 1.3.0   2019-11-21 [1] CRAN (R 4.0.2)
#>  usethis       1.6.1   2020-04-29 [1] CRAN (R 4.0.2)
#>  utf8          1.1.4   2018-05-24 [1] CRAN (R 4.0.0)
#>  vctrs         0.3.2   2020-07-15 [1] CRAN (R 4.0.2)
#>  withr         2.2.0   2020-04-20 [1] CRAN (R 4.0.0)
#>  xfun          0.16    2020-07-24 [1] CRAN (R 4.0.2)
#>  xml2          1.3.2   2020-04-23 [1] CRAN (R 4.0.0)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

Thanks for trying this out and replying. I am wondering if it is operating system dependent and only occurs in windows; I saw you are using macOS, with a different locale (en_US.UTF-8).

I do see this on Windows 10, R 4.0.2. US locale, by the way.

> minimal.example.data <- tidyr::tribble(
+   ~var1, ~var2,
+   "\U2265", "\U2264"
+ )
> View(minimal.example.data)
> knitr::kable(minimal.example.data)


|var1 |var2 |
|:----|:----|
|=    |=    |

Thanks for trying. So it might be a Windows problem. It also occurs in plane R (outside Rstudio). My Rstudio is standard set to UTF-8 (if it matters; I checked it).

I just came across another question with this similar problem, but no solution posted, from 2019:

My goal is to print this greater than or equal sign in a knitr::kable() table , using R/Rstudio my own windows computer; I need it to work with HTML and pdf output.

I hope someone can help with a solution!

For future reference: I started a topic on Stackoverflow, also showing some workarounds for specific cases that work for my data (although the workaround are a bit inconvenient).

I think that until UTF-8 in R under windows is fully supported (see here), there are no general solutions under windows. I'd be happy if someone proves me wrong on this though.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.