2

I have a function that prints some unicode characters to the console. This works perfectly fine when executed in the console, but when I run the same command in a chunk in an R markdown document some of the characters don't display correctly.

Here is a toy example:

test <- function() cat("\U003BC \U002260 \U003C0\n")

when run in the R console shows μ ≠ π, but when run in a chunk it does the mu correctly but not the other two, see attached screenshot.

enter image description here

Update: thanks for the replies so far. It seems that this is an issue with base R on Windows. The suggestion to use

knitr::asis_output(test1())

works. I also tried to use the chunk option results='asis', but this does not work, so somehow there is a difference between these two.

At least I now have a way to do what I want, except that I need to rewrite a number of routines to return the character string instead of using cat to print it.

Wolfgang Rolke
  • 795
  • 4
  • 16

0 Answers0