gt() doesn’t show Euro-Sign € in PDF, showing EUR instead

[This article was first published on rstats-tips.net, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

When it comes to using tidyverse in non-American contexts it gets often a little bit tricky. The last time I encountered a problem was when I tried to show the Euro-sign (€) in a PDF created with quarto and the gt-package.

Using html as output format everything was fine, but when I tried to create a PDF the Euro-sign was replaced by EUR.

There’s already an open issue at github ([ https://github.com/rstudio/gt/issues/1345]). But it’s getting pushed further and further down on the list of expected release versions.

So I had to find a workaround. The easiest way for me was to use fmt_number() followed by text_transfor() instead of fmt_currency().

So I format the columns with fmt_number() and then add the Euro-sign using paste0() and the unicode for the Euro-sign (\u20AC).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
data %>%
  gt() %>%
  fmt_number(
    columns = c(some_currency_column, another_currency_column),
    sep_mark = ".",
    dec_mark = ",",
  ) %>% 
  text_transform(
    fn = function(x) paste0(x, " \u20AC"),
    locations = cells_body(
      columns = c(some_currency_column, another_currency_column)
    )
To leave a comment for the author, please follow the link and comment on their blog: rstats-tips.net.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)