Incorrect Encoding Used in learnr Tutorials


I'm currently working on a tutorial package that uses learnr to create the tutorials.

However, whenever the tutorials are rendered, they use the default encoding for the system despite the files being saved in UTF-8 following the process described here: Shiny - Unicode characters in Shiny apps.

This obviously leads to problems like the one shown below.

Currently, when I reinstall the package and build the tutorial again, the tutorial's HTML file has the encoding error built in despite the overall HTML file using the UTF-8 charset. When I inspect the element with the encoding error, the HTML code looks like this:

<p>The Terminal tab will have a dollar sign (<code>$</code>) as the prompt. If it doesn’t have that and instead uses an arrow (<code>&gt;</code>), you may have to check your global options.</p>

This does not appear when I render the tutorial using the rmarkdown::render() command, lending me to believe that there's a problem with the way that I set up learnr's rendering system.

Is there a way that I can force learnr to use the UTF-8 encoding?

I've attached my session info below.

Thank you!

#> 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_United States.1252 
#> [2] LC_CTYPE=English_United States.1252   
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C                          
#> [5] 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] ps_1.6.0          digest_0.6.27     withr_2.4.2       magrittr_2.0.1   
#>  [5] reprex_2.0.0      evaluate_0.14     highr_0.9         stringi_1.6.2    
#>  [9] rlang_0.4.11      cli_2.5.0         rstudioapi_0.13   fs_1.5.0         
#> [13] rmarkdown_2.8     tools_4.1.0       stringr_1.4.0     glue_1.4.2       
#> [17] xfun_0.23         yaml_2.2.1        compiler_4.1.0    htmltools_0.5.1.1
#> [21] knitr_1.33

Created on 2021-07-06 by the reprex package (v2.0.0)


Can you provide an example Rmd file that reproduce the issue for you ?
Currently, I tried adding doesn't in learnr template doc created with RStudio but I can't reproduced the issue. It all appears correctly for me.

Also, can you update rmarkdown and maybe other package involved ? You are using 2.8 and 2.9 is out.
I also don't see the learnr version in your session info

Thanks !

The rmarkdown package was the problem, I updated the package to 2.9 and it worked fine.

Thank you so much for your help!

Even with this content I can't reproduce.

rmarkdown assumes that the input files is UTF8 and will only handle UTF8 input/output. So you just need to make sure your Rmd is correctly UTF-8 encoded.

Can you share a whole file with somehow so that it keeps its encoding as copy pasting doesn't work ?

We should try to look at the real encoding of generated HTML file in your system. I think you should get a HTML file right next your Rmd file when running rmarkdown::run. If you open in an editor you should be able to check the encoding of this file.

Encoding issue can be very system / local dependant so it is hard to look into without being able to reproduce

Oh I did see that you edited the post.

Next time, add an answer without editing. I think it is great to keep history of dicussion too.
my previous answer makes no sense now :sweat_smile:

Anyway, Happy that it works as expected

Sorry for the confusion, I forgot to update the renv file and it didn't work so I thought updating packages didn't change anything. Thank you though!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.