[NTG-context] Filter module for R
Aditya Mahajan
adityam at umich.edu
Mon Jun 15 08:04:40 CEST 2020
On Mon, 15 Jun 2020, Aditya Mahajan wrote:
> On Sun, 14 Jun 2020, Fabrice L wrote:
>
>> Hi,
>>
>> Following a question about the broken R module (R the statistical
>> software), Aditya suggested me the filter module (thanks to him). I’m about
>> to distribute a set of course notes to colleagues, and I need to deal with
>> details now. I have one problem and two questions.
>>
>> 1) the filter collect R code between \startR / \stopR and submit this code
>> to R. As it can be seen in the following minimal example, when a label
>> contains an accented character (« Fréquence » in my example), the pdf
>> graphic does not contains the « é ». Strangely, the snippet of code (which
>> is saved locally as « test2-temp-R-0.tmp » (for test2.tex)) when submitted
>> with the same command as the filtercommand, works correctly; that means the
>> same file works when submitted to R outside of ConTeXt. I have no idea how
>> to solve this.
>
> Are you running the exact same command as the `filtercommand`. If so, I don't
> know why running the `filtercommand` through context vs directly typing it on
> the terminal should behave differently. The filter module effectively just
> runs os.execute("filtercommand"). I don't use R so I am unable to debug
> further.
I can reproduce this output side the filter module. If I directly run os.execute(...) from a lua session, the output is correct but running it through context gives the wrong output. I am guessing this is something to do with locale. I notice that the output of os.execute("locale") from context is different from that from my shell. But I don't know why locale should affect UTF characters in R. Perhaps someone with more knowledge of R can comment on that.
\starttext
\startluacode
lfs.mkdir("output/")
\stopluacode
\startbuffer[code]
pdf("output/MyHistogram.pdf",5,5)
X <- rnorm(200,mean=10,sd=2)
hist(X, col = "red3" , xlab="Score QI" , main="", ylab="fréquence")
\stopbuffer
\savebuffer[prefix=no, list=code, file={output/code.r}]
\startluacode
print(">>>>", "RUNNING R CMD")
os.execute("R CMD BATCH --no-timing --save --restore output/code.r output/out")
\stopluacode
\externalfigure[RPlots/MyHistogram.pdf][width=.5\textwidth]
\stoptext
Aditya
More information about the ntg-context
mailing list