From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107725 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 01:45:09 -0400 (EDT) Message-ID: References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-1498671910-1592199910=:1528" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="23759"; 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 07:45:37 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 1jkhw9-000660-CM for gctc-ntg-context-518@m.gmane-mx.org; Mon, 15 Jun 2020 07:45:37 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 0FF78163B11; Mon, 15 Jun 2020 07:45:16 +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 QezWoEtSfLXM; Mon, 15 Jun 2020 07:45:15 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 1A37F163A7C; Mon, 15 Jun 2020 07:45:15 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id CE642163A7C for ; Mon, 15 Jun 2020 07:45:13 +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 bNo2bDfEATeL for ; Mon, 15 Jun 2020 07:45:13 +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 040FD162E6F for ; Mon, 15 Jun 2020 07:45:12 +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 7F014F78C1 for ; Mon, 15 Jun 2020 01:45:10 -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:107725 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-1498671910-1592199910=:1528 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Sun, 14 Jun 2020, Fabrice L wrote: > Hi, > > Following a question about the broken R module (R the statistical softwar= e), Aditya suggested me the filter module (thanks to him). I=E2=80=99m abou= t to distribute a set of course notes to colleagues, and I need to deal wit= h details now. I have one problem and two questions. > > 1) the filter collect R code between \startR / \stopR and submit this cod= e to R. As it can be seen in the following minimal example, when a label co= ntains an accented character (=C2=AB Fr=C3=A9quence =C2=BB in my example), = the pdf graphic does not contains the =C2=AB =C3=A9 =C2=BB. Strangely, the = snippet of code (which is saved locally as =C2=AB test2-temp-R-0.tmp =C2=BB= (for test2.tex)) when submitted with the same command as the filtercommand= , works correctly; that means the same file works when submitted to R outsi= de 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 deb= ug further. > 2) In a teaching context, we may want sometimes to show the code. The fil= ter module actually permits to show the output of the code submitted to R (= which can include or not the input commands); would it be possible to types= et the submitted code ? This is an adapted version of the code that I use for my course where I use= the vim module to do the typesetting: \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] [ syntax=3Dr, directory=3Doutput, strip=3Dyes, escape=3Dyes, before=3D{\blank[quarterline]\startleftbartext}, after=3D{\stopleftbartext}, ] \define[1]\ShowOutput {\typeRCODEfile{\externalfilterinputfile} \startleftbartext[framecolor=3Ddarkgreen, backgroundcolor=3Dlightgree= n] \setupalign[flushleft, verytolerant] % range=3D{1,-1} not currently supported % See below for details \typefile[range=3D{1,-1}]{#1} \stopleftbartext} \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, cache=3Dyes, purge=3Dyes, % THE COMMA WAS MISSING ] \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 > 3) Finally, using "R CMD BATCH=E2=80=A6 =C2=BB as the filtercommand add a= n extra line at the end of the output file which can be typeset to visualiz= e results. Would it be possible by a magic trick to deleter the last line o= f the file ? It is possible to filter lines using `\typefile[range=3D{start, stop}]{file= name}`. You can use `range=3D{1,3}` to only include lines 1 upto 3 or `rang= e=3D{1, +2}` to include line 1 followed by 2 lines. What you want is someth= ing like `range=3D{1,-1}`, i.e., include from the first to last-1 line, but= this is not currently supported. You could ask Hans to do so, as it is rel= atively simple to add. Of course, you will then need to document this on th= e wiki. Aditya --8323329-1498671910-1592199910=: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-1498671910-1592199910=:1528--