Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unicode.symbol shows ISO 3166-1 alpha-2 notation instead of flags #331

Open
rempsyc opened this issue Jun 11, 2023 · 12 comments
Open

unicode.symbol shows ISO 3166-1 alpha-2 notation instead of flags #331

rempsyc opened this issue Jun 11, 2023 · 12 comments

Comments

@rempsyc
Copy link

rempsyc commented Jun 11, 2023

Hello Vincent! I'm glad I finally get to use your countrycode package!

I am having an issue with the country flags unicode.symbol. I know that your README mentions:

Since inserting unicode symbols into R graphics is not a countrycode-specific issue, we won’t be able to offer any more support than this. Good luck!

But I believe the example provided (gt table) is not R graphics. You will see in the example below that instead of showing the country flags, like this:

It only shows their ISO 3166-1 alpha-2 notation (CA, DE, etc.):

library(gt)
library(countrycode)
packageVersion("countrycode")
#> [1] '1.5.0'

Countries <- c('Canada', 'Germany', 'Thailand', 'Algeria', 'Eritrea')
Flags <- countrycode(Countries, 'country.name', 'unicode.symbol')
dat <- data.frame(Countries, Flags)
gt(dat)
Countries Flags
Canada 🇨🇦
Germany 🇩🇪
Thailand 🇹🇭
Algeria 🇩🇿
Eritrea 🇪🇷

Created on 2023-06-11 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.0 (2023-04-21 ucrt)
#>  os       Windows 10 x64 (build 19045)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_Canada.utf8
#>  ctype    English_Canada.utf8
#>  tz       America/Toronto
#>  date     2023-06-11
#>  pandoc   3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.1   2023-03-23 [1] CRAN (R 4.3.0)
#>  countrycode * 1.5.0   2023-05-30 [1] CRAN (R 4.3.0)
#>  digest        0.6.31  2022-12-11 [1] CRAN (R 4.3.0)
#>  dplyr         1.1.2   2023-04-20 [1] CRAN (R 4.3.0)
#>  evaluate      0.21    2023-05-05 [1] CRAN (R 4.3.0)
#>  fansi         1.0.4   2023-01-22 [1] CRAN (R 4.3.0)
#>  fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.2   2023-04-25 [1] CRAN (R 4.3.0)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.3.0)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.3.0)
#>  gt          * 0.9.0   2023-03-31 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.5   2023-03-23 [1] CRAN (R 4.3.0)
#>  knitr         1.43    2023-05-25 [1] CRAN (R 4.3.0)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.0)
#>  pillar        1.9.0   2023-03-22 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.3.0)
#>  purrr         1.0.1   2023-01-10 [1] CRAN (R 4.3.0)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.3.0)
#>  R.utils       2.12.2  2022-11-11 [1] CRAN (R 4.3.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.3.0)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang         1.1.1   2023-04-28 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.22    2023-06-01 [1] CRAN (R 4.3.0)
#>  rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.3.0)
#>  sass          0.4.6   2023-05-03 [1] CRAN (R 4.3.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.0)
#>  styler        1.9.1   2023-03-04 [1] CRAN (R 4.3.0)
#>  tibble        3.2.1   2023-03-20 [1] CRAN (R 4.3.0)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.3.0)
#>  utf8          1.2.3   2023-01-31 [1] CRAN (R 4.3.0)
#>  vctrs         0.6.2   2023-04-19 [1] CRAN (R 4.3.0)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.3.0)
#>  xfun          0.39    2023-04-20 [1] CRAN (R 4.3.0)
#>  xml2          1.3.4   2023-04-27 [1] CRAN (R 4.3.0)
#>  yaml          2.3.7   2023-01-23 [1] CRAN (R 4.3.0)
#> 
#>  [1] C:/Users/there/AppData/Local/R/win-library/4.3
#>  [2] C:/Program Files/R/R-4.3.0/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Any idea why this might be the case? Could there be something wrong on my system?

@vincentarelbundock
Copy link
Owner

@rempsyc good to see you here! You’re right, those are not R graphics. They are emojis encoded as Unicode characters. You need a device that will display them properly.

On GitHub your example appears fine to me.

@rempsyc
Copy link
Author

rempsyc commented Jun 11, 2023

Oh really? This is how they appear to me on GitHub...

flags

Any suggestion as to how to fix my device to display them correctly?

@rempsyc
Copy link
Author

rempsyc commented Jun 11, 2023

And in RStudio:

rstudio

@vincentarelbundock
Copy link
Owner

That's weird. It works for me on my Windows machine, on the Github App in iPhone, and in Safari on iPhone. Some links on Google suggest you may need to install fonts that support the emoji unicodes, but frankly I'm not sure exactly what to recommend.

@NilsEnevoldsen
Copy link
Contributor

What OS (including version) are you using? How does https://emojipedia.org/flags/ look?

@NilsEnevoldsen
Copy link
Contributor

Actually, @vincentarelbundock, what OS version and browser are you using? Windows 10+ doesn't ship with flag emojis for political reasons. Firefox ships their own emoji font to plug that hole, but most other browsers don't. I don't know what fonts RStudio uses by default. I don't have a Windows computer to test.

@vincentarelbundock
Copy link
Owner

Actually, @vincentarelbundock, what OS version and browser are you using? Windows 10+ doesn't ship with flag emojis for political reasons. Firefox ships their own emoji font to plug that hole, but most other browsers don't. I don't know what fonts RStudio uses by default. I don't have a Windows computer to test.

Ah yes! I was using Windows 11 with Firefox. So I guess I'm benefiting from the built-in emoji font.

@rempsyc
Copy link
Author

rempsyc commented Jun 12, 2023

Hum, I see. I can confirm that I can see it correctly on my phone OR using Firefox, but not any of the other browsers.

Vincent just to be thorough, what does it look like within the RStudio viewer for you?

If the flags don't appear correctly within RStudio for all Windows users (and most browsers), would this be worth a note in the readme since there might be a lot of confused users?

On my end it is suddenly a bit less practical to use Unicode flags (damn Windows!!), I guess I'll need to rely on actual images of the flags for my purposes...

@NilsEnevoldsen
Copy link
Contributor

I would be curious to know if installing Noto Color Emoji on the system would cause them to be shown in RStudio. Restarting RStudio might be required.

(I think this won't work for most Chromium-based browsers, since they only fall back to official system fonts, but I don't know how RStudio selects fonts.)

@vincentarelbundock
Copy link
Owner

Vincent just to be thorough, what does it look like within the RStudio viewer for you?

Turns out Rstudio does not display them. (I never use Rstudio so had not noticed.)

would this be worth a note in the readme since there might be a lot of confused users?

Yes, I think that's a good idea.

@NilsEnevoldsen
Copy link
Contributor

And, just for completeness, RStudio does display them on macOS. (At least it does for me. I think it would do it out-of-the-box.)

@rempsyc
Copy link
Author

rempsyc commented Jun 12, 2023

I would be curious to know if installing Noto Color Emoji on the system would cause them to be shown in RStudio. Restarting RStudio might be required.

So I installed Noto Color Emoji and restarted RStudio, but still no luck. It seems RStudio doesn't automatically change font if some emojis are not available.

Anyway, glad I was able to to make a small contribution by shedding light on the user experience of most Windows users ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants