Cannot generate UTF-8 characters such as Chinese
everdark opened this issue · comments
Kyle Chung commented
Hi,
It seems that the meta
function is not able to properly generate UTF-8 characters on Windows.
Here is a minimally reproducible example:
---
title: "test"
date: "6/13/2020"
output: html_document
---
```{r open_graph_meta, include=FALSE}
# Add open graph meta information to the page.
library(metathis)
meta() %>%
meta_description(
"這裡") %>%
meta_viewport() %>%
meta_social(
og_type="book",
og_locale="zh_TW",
twitter_card_type="summary"
)
```
The resulting document will have og meta tag looks like this:
<meta name="viewport" content="width=device-width, initial-scale=1, orientation=auto" />
<meta name="description" content="<U+9019><U+88E1>" />
<meta name="twitter:description" content="<U+9019><U+88E1>" />
<meta name="twitter:card" content="summary" />
<meta name="og:description" content="<U+9019><U+88E1>" />
<meta name="og:type" content="book" />
<meta name="og:locale" content="zh_TW" />
However under RStudio the meta
function CAN correctly print those characters to console.
So I'm not sure what went wrong...
My platform info:
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] metathis_1.0.2
loaded via a namespace (and not attached):
[1] compiler_3.6.2 magrittr_1.5 htmltools_0.4.0.9003 tools_3.6.2 yaml_2.2.1
[6] rmarkdown_2.2.0 knitr_1.28 digest_0.6.25 xfun_0.14 rlang_0.4.6
[11] evaluate_0.14 purrr_0.3.3
Kyle Chung commented
Ok I think the workaround is just to put a .Rprofile
under the same directory with the following line:
Sys.setlocale("LC_CTYPE", "Chinese (Traditional)_Taiwan.950")