cynkra / indiedown

Individual RMarkdown Templates
https://indiedown.cynkra.com
Other
30 stars 1 forks source link

Warning prints onto PDF #22

Open ailich opened 2 years ago

ailich commented 2 years ago

When I create the mydown package as in the example, and then use the template without any editing, I'm getting an R code warning printed at the top

Screenshot 2022-01-14 170908

sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

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     

loaded via a namespace (and not attached):
 [1] compiler_4.0.4  fastmap_1.1.0   mydown_0.1      htmltools_0.5.2 tools_4.0.4     yaml_2.2.1      rmarkdown_2.11  knitr_1.36     
 [9] xfun_0.23       digest_0.6.27   rlang_0.4.10    evaluate_0.14 
krlmlr commented 2 years ago

Thanks for the report. This looks like a problem that would only occur on Windows.

We need to think more about the mapping language to locale in a platform-independent way.

Can you please tweak the generated cd_format_date() function to use a supported locale, e.g. "English_United States.1252" ?

christophsax commented 2 years ago

I think cd_format_date() should not rely on the system, but instead do something as discussed in https://github.com/cynkra/indiedown/issues/12.

ailich commented 2 years ago

@krlmlr changing "en_US" to "English_United States.1252" removed the warning for me on Windows.

cd_format_date <- function(date, lang = default(rmarkdown::metadata$lang, "en-US")) {
  date <- as.Date(date)
  if (lang %in% c("german", "de-DE", "de-CH")) {
    withr::with_locale(c("LC_TIME" = "de_DE"), format(date, "%e. %B %Y"))
  } else {
    withr::with_locale(c("LC_TIME" = "English_United States.1252"), format(date, "%B %e, %Y"))
  }
}