adityam / filter

ConTeXt module to process contents of a start-stop environment through an external program
45 stars 10 forks source link

Accents are not displayed when using filter with R #44

Closed fthalabi closed 3 years ago

fthalabi commented 3 years ago

Minimal example to reproduce the issue:


\usemodule[filter]

\startbuffer[r::before]
library(tidyverse)
\stopbuffer

\defineexternalfilter
  [R]
  [filtercommand={R CMD BATCH  \externalfilterinputfile\space \externalfilteroutputfile},
   output=\externalfilterbasefile.out,
   bufferbefore={r::before},
   continue=no,
   read=no]

\starttext

\startR
dt <- tibble(x = 1:5, y = x)
plot <- ggplot(data = dt, mapping = aes(x = x, y = y, color = factor(x))) + geom_point() + labs(title = "áéíóú")
ggsave('plot.pdf',plot = plot, device = cairo_pdf,width = 5,height=5,unit='cm')
\stopR

\externalfigure[plot.pdf]
\stoptext

The context output: image

The same R code run with Rscript gives:

image

I would be very grateful for any help in this issue, because i don't wanna waste anyone time i tried to solve it myself, but i couldn't.

Thanks in advance, Fernando H.

adityam commented 3 years ago

Most likely because the locale seen by context is different from your system locale. Try adding

Sys.setlocale(category="LC_ALL", locale="en_US.UTF-8")

in r::before.

fthalabi commented 3 years ago

You are right, it works. Thanks.