From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107727 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Aditya Mahajan Newsgroups: gmane.comp.tex.context Subject: Re: Filter module for R Date: Mon, 15 Jun 2020 02:24:31 -0400 (EDT) Message-ID: References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-418524315-1592202271=:1528" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="52209"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Alpine 2.22 (LNX 432 2020-05-21) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Mon Jun 15 08:24:57 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jkiYC-000DUn-OP for gctc-ntg-context-518@m.gmane-mx.org; Mon, 15 Jun 2020 08:24:56 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 853E1163906; Mon, 15 Jun 2020 08:24:36 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qc84XkJ9LBSN; Mon, 15 Jun 2020 08:24:35 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 9072D163AC7; Mon, 15 Jun 2020 08:24:35 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 8EE63163AC7 for ; Mon, 15 Jun 2020 08:24:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uo7i9CGRY1kV for ; Mon, 15 Jun 2020 08:24:33 +0200 (CEST) Received-SPF: Softfail (mailfrom) identity=mailfrom; client-ip=132.206.73.2; helo=orford.cim.mcgill.ca; envelope-from=adityam@umich.edu; receiver= Original-Received: from orford.cim.mcgill.ca (orford.cim.mcgill.ca [132.206.73.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id BF482163906 for ; Mon, 15 Jun 2020 08:24:32 +0200 (CEST) Original-Received: from adi-thinkpad.local (198-84-255-218.cpe.teksavvy.com [198.84.255.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adityam) by orford.cim.mcgill.ca (Postfix) with ESMTPSA id 63692F78C1 for ; Mon, 15 Jun 2020 02:24:31 -0400 (EDT) In-Reply-To: X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:107727 Archived-At: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-418524315-1592202271=:1528 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Mon, 15 Jun 2020, Aditya Mahajan wrote: > On Mon, 15 Jun 2020, Aditya Mahajan wrote: > >> On Sun, 14 Jun 2020, Fabrice L wrote: >>=20 >>> Hi, >>>=20 >>> Following a question about the broken R module (R the statistical=20 >>> software), Aditya suggested me the filter module (thanks to him). I=E2= =80=99m=20 >>> about to distribute a set of course notes to colleagues, and I need to= =20 >>> deal with details now. I have one problem and two questions. >>>=20 >>> 1) the filter collect R code between \startR / \stopR and submit this c= ode=20 >>> to R. As it can be seen in the following minimal example, when a label= =20 >>> contains an accented character (=C2=AB Fr=C3=A9quence =C2=BB in my exam= ple), the pdf=20 >>> graphic does not contains the =C2=AB =C3=A9 =C2=BB. Strangely, the snip= pet of code (which=20 >>> is saved locally as =C2=AB test2-temp-R-0.tmp =C2=BB (for test2.tex)) w= hen submitted=20 >>> with the same command as the filtercommand, works correctly; that means= =20 >>> the same file works when submitted to R outside of ConTeXt. I have no i= dea=20 >>> how to solve this. >>=20 >> Are you running the exact same command as the `filtercommand`. If so, I= =20 >> don't know why running the `filtercommand` through context vs directly= =20 >> typing it on the terminal should behave differently. The filter module= =20 >> effectively just runs os.execute("filtercommand"). I don't use R so I am= =20 >> unable to debug further. > > I can reproduce this output side the filter module. If I directly run=20 > os.execute(...) from a lua session, the output is correct but running it= =20 > through context gives the wrong output. I am guessing this is something t= o do=20 > with locale. I notice that the output of os.execute("locale") from contex= t is=20 > different from that from my shell. But I don't know why locale should aff= ect=20 > UTF characters in R. It is indeed related to locale. Here is a minimal example that works. I use= a beforebuffer to set the locale so that you don't have to do it in each s= nippet and then filter out the first line in the typeset code listing and f= ilter out the first two lines in the output. \usemodule[filter] \usemodule[vim] \definecolor [darkblue] [r=3D0.1, g=3D0.11, b=3D0.84] \definecolor [darkgreen] [g=3D0.7] \definecolor [lightblue] [h=3D87cefa] \definecolor [lightgreen] [g=3D0.95,b=3D0.8,r=3D0.8] \defineframedtext [leftbartext] [ width=3Dlocal, frame=3Doff, framecolor=3Ddarkblue, leftframe=3Don, rulethickness=3D1ex, offset=3D0.25ex, loffset=3D3ex, background=3Dcolor, backgroundcolor=3Dlightblue, ] \definevimtyping [RCODE] [ vimcommand=3Dnvim, syntax=3Dr, directory=3Doutput, strip=3Dyes, escape=3Dyes, before=3D{\blank[quarterline]\startleftbartext}, after=3D{\stopleftbartext}, ] \define[1]\ShowOutput {\typeRCODEfile[start=3D2]{\externalfilterinputfile} \startleftbartext[framecolor=3Ddarkgreen, backgroundcolor=3Dlightgree= n] \setupalign[flushleft, verytolerant] \typefile[range=3D{3,-1}]{#1} \stopleftbartext} \startbuffer[locale] Sys.setlocale(category=3D"LC_ALL", locale=3D"en_US.UTF-8") \stopbuffer \defineexternalfilter [R] [ filtercommand=3D{R CMD BATCH -q --no-timing --save --restore \externalfilterinputfile\space \externalfilteroutputfile}, output=3D\externalfilterbasefile.out, directory=3Doutput, readcommand=3D\ShowOutput, read=3Dno, bufferbefore=3Dlocale, cache=3Dyes, purge=3Dyes, ] \starttext Some text... \startR[read=3Dyes] pdf("RPlots/MyHistogram.pdf",5,5) X <- rnorm(200,mean=3D10,sd=3D2) hist(X, col =3D "red3" , xlab=3D"Score QI" , main=3D"", ylab=3D"fr=C3= =A9quence") \stopR \externalfigure[RPlots/MyHistogram.pdf][width=3D.5\textwidth] \stoptext Aditya --8323329-418524315-1592202271=:1528 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --8323329-418524315-1592202271=:1528--