2

Related to this question.

After looking to answer the linked question I noticed the following behaviour:

> '\u226A'
[1] "≪"

but while trying to plot the same symbol, I received the most beautiful of squares instead

plot(1, 1, main = '\u226A')

failing-unicode-title

meanwhile if I instead wrap it in an empty expression, it prints the symbol correctly

plot(1, 1, main = expression('\u226A' ~ ''))

working-unicode-title

My question is simply "Why" it works in the console, fails in the first plot and works in the latter?

> Sys.info()
          sysname           release           version          nodename           machine 
        "Windows"          "10 x64"     "build 19043" "LAPTOP-NGIP5B78"          "x86-64" 
            login              user    effective_user 
          "olive"           "olive"           "olive" 
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_Denmark.1252  LC_CTYPE=English_Denmark.1252   
[3] LC_MONETARY=English_Denmark.1252 LC_NUMERIC=C                    
[5] LC_TIME=English_Denmark.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.1.0   tools_4.1.0      Rcpp_1.0.6       cellranger_1.1.0 readxl_1.3.1    
Oliver
  • 8,169
  • 3
  • 15
  • 37

1 Answers1

3

Change the encoding to native:

a <- '\u226A'
# this shows as a square in R windows console
# but not when posted into browser so I can't easily show it
a

Encoding(a)
## [1] "UTF-8"

b <- enc2native(a)
Encoding(b)
## [1] "latin1"

b
## [1] "«"

Also these work:

plot(0, main = ~ '\u226A')
plot(0, main = bquote(.(b)))
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
  • Interesting, it works. Also interesting that you get a square in the R-console while I don't. Either way thank you Grothendieck – Oliver Jul 27 '21 at 21:34