emo
emo copied to clipboard
Windows woes: emojis render inline but not in blocks
I have no doubt that this problem is due to something further upstream but I don't know exactly what. I have tried saving the Rmd file with every possible encoding.
Minimal working example on Windows
Block emojis:
```{r, collapse = TRUE}
emo::ji('poop')
emo:::emoji_name['poop']
```
And inline: `r emo::ji('poop')`
Returns something that looks like this
Block emojis:
emo::ji('poop')
## <f0><U+009F><U+0092><U+00A9>
emo:::emoji_name['poop']
## poop
## "<f0><U+009F><U+0092><U+00A9>"
And inline: 💩
Searching online, the only other report of this issue that I could find, with unicode code points (if that's the correct term) being coerced into angle brackets is here.
I have noticed that the behaviour is different in the console and in knitting Rmd files. If I simply enter the following into the console:
emo:::emoji_name['poop']
then the output is
poop
"\xf0\u009f\u0092�"
but, still in the console,
enc2native(emo:::emoji_name['poop'])
returns
poop
"<f0><U+009F><U+0092><U+00A9>"
which looks like the Rmarkdown output, above.
So it looks like for block text output Rmarkdown/Knitr is parsing (multi-byte?) unicode characters differently to inline, with the result that on Windows, emo
works inline but not in chunks.
I guess this should be reported to hadley/evaluate, which is used inside knitr.
evaluate:::evaluate_call(expression(emo::ji('poop')), NULL, globalenv(), baseenv())
[[1]]
$src
NULL
attr(,"class")
[1] "source"
[[2]]
[1] "<f0><U+009F><U+0092><U+00A9> \n"
And the bellow is basically the same as what evaluate:::watchout()
does. I doubt textConnection()
can handle emojis, since it does some text conversion which makes us unhappy...
output <- character()
con <- textConnection("output", "wr", local = TRUE)
capture.output(print(emo::ji('poop')), file = con)
close(con)
output
#> [1] "<f0><U+009F><U+0092><U+00A9> "