ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Removing banner from mtxrun output
@ 2010-09-20  8:26 Johan Sandblom
  2010-09-20  8:44 ` luigi scarso
  2010-09-20  9:17 ` Aditya Mahajan
  0 siblings, 2 replies; 11+ messages in thread
From: Johan Sandblom @ 2010-09-20  8:26 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]

Greetings all!

In the modernized version of the R module (attached), which makes it
possible to interact with the statistical programming environment R
(http://www.r-project.org), mtxrun is used to call R on saved buffers
containing snippets of R code. Optionally, the output from R can be
included using \typefile. However, mtxrun includes a banner in the
output file, example below.

MTXrun |
MTXrun | executing: R -q --save --restore
MTXrun |
MTXrun |> sample(1:10)
 [1]  5  3  1  9  2  6 10  8  4  7
> sample(1:10, replace=TRUE)
 [1]  1 10  7  1  7  5  2  2 10  5
>

If the results of the computations are to be included in the text,
this banner is ugly and distracting.

Question: is it possible to instruct mtxrun not to make such a banner?
Or, alternatively, is there an easy way to remove it before the text
is included?

I am using MKIV exclusively.

Regards, Johan

-- 
Johan Sandblom, MD PhD
m +46735521477  Sweden
"What is wanted is not the will to believe, but the
will to find out, which is the exact opposite"
- Bertrand Russell

[-- Attachment #2: m-r.tex --]
[-- Type: application/x-tex, Size: 4244 bytes --]

[-- Attachment #3: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-20  8:26 Removing banner from mtxrun output Johan Sandblom
@ 2010-09-20  8:44 ` luigi scarso
  2010-09-20  9:23   ` Aditya Mahajan
  2010-09-20 20:56   ` Johan Sandblom
  2010-09-20  9:17 ` Aditya Mahajan
  1 sibling, 2 replies; 11+ messages in thread
From: luigi scarso @ 2010-09-20  8:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, Sep 20, 2010 at 10:26 AM, Johan Sandblom <jsandblom@gmail.com> wrote:
> Greetings all!
>
> In the modernized version of the R module (attached), which makes it
> possible to interact with the statistical programming environment R
> (http://www.r-project.org), mtxrun is used to call R on saved buffers
> containing snippets of R code. Optionally, the output from R can be
> included using \typefile. However, mtxrun includes a banner in the
> output file, example below.
>
> MTXrun |
> MTXrun | executing: R -q --save --restore
> MTXrun |
> MTXrun |> sample(1:10)
>  [1]  5  3  1  9  2  6 10  8  4  7
>> sample(1:10, replace=TRUE)
>  [1]  1 10  7  1  7  5  2  2 10  5
>>
>
> If the results of the computations are to be included in the text,
> this banner is ugly and distracting.
>
> Question: is it possible to instruct mtxrun not to make such a banner?
> Or, alternatively, is there an easy way to remove it before the text
> is included?
>
> I am using MKIV exclusively.
>
> Regards, Johan
A bit off-topic:
do you know aditya module t-filters ?
See
http://meeting.contextgarden.net/2010/talks/2010-09-15-aditya-filters/

-- 
luigi
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-20  8:26 Removing banner from mtxrun output Johan Sandblom
  2010-09-20  8:44 ` luigi scarso
@ 2010-09-20  9:17 ` Aditya Mahajan
  2010-09-20 20:02   ` Johan Sandblom
  1 sibling, 1 reply; 11+ messages in thread
From: Aditya Mahajan @ 2010-09-20  9:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, 20 Sep 2010, Johan Sandblom wrote:

> In the modernized version of the R module (attached), which makes it
> possible to interact with the statistical programming environment R
> (http://www.r-project.org), mtxrun is used to call R on saved buffers
> containing snippets of R code. Optionally, the output from R can be
> included using \typefile. However, mtxrun includes a banner in the
> output file, example below.

Why are you using input output redirection

       R .... < \Rfile\space > \Rfile.out

rather than a simple

      R .... \Rfile\space \Rfile.out

> MTXrun |
> MTXrun | executing: R -q --save --restore
> MTXrun |
> MTXrun |> sample(1:10)
> [1]  5  3  1  9  2  6 10  8  4  7
>> sample(1:10, replace=TRUE)
> [1]  1 10  7  1  7  5  2  2 10  5


See 
http://archive.contextgarden.net/message/20100611.141914.fd6567be.en.html

but the banner still appears the first time mtxrun --ifchanged is run.

@Hans, mtxrun be completely silent when used to launch external 
programs and only give some output if --verbose is passed.


BTW, there is a serious bug in the R module: each code chunck carries a 
state with it (--save --restore), but this state can depend on which 
chunck was changed.

Consider (I don't know the R syntax on top of my head, but this gives the 
idea of the bug)

Chunk 1
\startR
  a = 10 ;
  b = 10 ;
\stopR

Chunk 2
\startR
  a = 20 ;
  b = 20
\stopR

Chunck 3
\startR
print(a+b) ;
\stopR

Run this once. The output will be 40. Now, add

c = 10 ;

in Chunk 1. Also change Chunk 3 to (add spaces so that md5 sum is 
different)

print( a + b ) ;

Now run the file again. Since Chunk 2 is not changed, it will not be run. 
Chunk 3 will see the state set by Chunk 1, and hence the output will be 
20.

This "bug" can be avoided by doing some book keeping for the external 
state (saving the file to a different name and restoring it), or by not 
using --save and --restore.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-20  8:44 ` luigi scarso
@ 2010-09-20  9:23   ` Aditya Mahajan
  2010-09-20 20:56   ` Johan Sandblom
  1 sibling, 0 replies; 11+ messages in thread
From: Aditya Mahajan @ 2010-09-20  9:23 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, 20 Sep 2010, luigi scarso wrote:

> A bit off-topic:
> do you know aditya module t-filters ?
> See
> http://meeting.contextgarden.net/2010/talks/2010-09-15-aditya-filters/

Also see
http://randomdeterminism.wordpress.com/2010/06/10/replacing-r-module/

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-20  9:17 ` Aditya Mahajan
@ 2010-09-20 20:02   ` Johan Sandblom
  0 siblings, 0 replies; 11+ messages in thread
From: Johan Sandblom @ 2010-09-20 20:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users

2010/9/20 Aditya Mahajan <adityam@umich.edu>:
> On Mon, 20 Sep 2010, Johan Sandblom wrote:

> Why are you using input output redirection
>
>      R .... < \Rfile\space > \Rfile.out
>
> rather than a simple
>
>     R .... \Rfile\space \Rfile.out

Originally, I think it was because it was the only way that worked on
both Windows and Linux, but lately it is because R CMD BATCH produces
produces a couple of lines of processing times at the end, which I do
not want.

> @Hans, mtxrun be completely silent when used to launch external programs and
> only give some output if --verbose is passed.

That would make more sense.

> BTW, there is a serious bug in the R module: each code chunck carries a
> state with it (--save --restore), but this state can depend on which chunck
> was changed.

Indeed. But I have learned to live with it.

> This "bug" can be avoided by doing some book keeping for the external state
> (saving the file to a different name and restoring it), or by not using
> --save and --restore.

Yes. But the book keeping gets a little complicated and ugly since it
needs to be done from within R (--save takes no arguments). Or
possibly all chunks after an altered chunk should be run.

Thanks for your comments, Johan

> Aditya
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>



-- 
Johan Sandblom, MD PhD
m +46735521477  Sweden
"What is wanted is not the will to believe, but the
will to find out, which is the exact opposite"
- Bertrand Russell
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-20  8:44 ` luigi scarso
  2010-09-20  9:23   ` Aditya Mahajan
@ 2010-09-20 20:56   ` Johan Sandblom
  2010-09-21 18:44     ` Johan Sandblom
  1 sibling, 1 reply; 11+ messages in thread
From: Johan Sandblom @ 2010-09-20 20:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users

> A bit off-topic:
> do you know aditya module t-filters ?
> See
> http://meeting.contextgarden.net/2010/talks/2010-09-15-aditya-filters/

I didn't, but I'll investigate!

Thank you, Johan

> --
> luigi
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>



-- 
Johan Sandblom, MD PhD
m +46735521477  Sweden
"What is wanted is not the will to believe, but the
will to find out, which is the exact opposite"
- Bertrand Russell
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-20 20:56   ` Johan Sandblom
@ 2010-09-21 18:44     ` Johan Sandblom
  2010-09-21 19:28       ` Peter Münster
  0 siblings, 1 reply; 11+ messages in thread
From: Johan Sandblom @ 2010-09-21 18:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users

The filters module works great! The R module should be abandoned in
favor of it. The only problem I have now is the problem with the
unwanted lines at the end of R output. Is there a way to instruct
\typefile to ignore the last four lines of the outputfile? I assume
defining an alternative command which does just that is not too
difficult, but sadly beyond me.

Johan

2010/9/20 Johan Sandblom <jsandblom@gmail.com>:
>> A bit off-topic:
>> do you know aditya module t-filters ?
>> See
>> http://meeting.contextgarden.net/2010/talks/2010-09-15-aditya-filters/
>
> I didn't, but I'll investigate!
>
> Thank you, Johan
>
>> --
>> luigi
>> ___________________________________________________________________________________
>> If your question is of interest to others as well, please add an entry to the Wiki!
>>
>> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
>> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
>> archive  : http://foundry.supelec.fr/projects/contextrev/
>> wiki     : http://contextgarden.net
>> ___________________________________________________________________________________
>>
>
>
>
> --
> Johan Sandblom, MD PhD
> m +46735521477  Sweden
> "What is wanted is not the will to believe, but the
> will to find out, which is the exact opposite"
> - Bertrand Russell
>



-- 
Johan Sandblom, MD PhD
m +46735521477  Sweden
"What is wanted is not the will to believe, but the
will to find out, which is the exact opposite"
- Bertrand Russell
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-21 18:44     ` Johan Sandblom
@ 2010-09-21 19:28       ` Peter Münster
  2010-09-21 20:18         ` Aditya Mahajan
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Münster @ 2010-09-21 19:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, Sep 21 2010, Johan Sandblom wrote:

> Is there a way to instruct
> \typefile to ignore the last four lines of the outputfile? I assume
> defining an alternative command which does just that is not too
> difficult, but sadly beyond me.

It seems, that it's not possible at the moment. There is a tracker item
for this feature: http://tracker.luatex.org/view.php?id=475
Cheers, Peter

-- 
Contact information: http://pmrb.free.fr/contact/


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-21 19:28       ` Peter Münster
@ 2010-09-21 20:18         ` Aditya Mahajan
  2010-09-21 20:37           ` Johan Sandblom
  2010-09-21 20:45           ` Hans Hagen
  0 siblings, 2 replies; 11+ messages in thread
From: Aditya Mahajan @ 2010-09-21 20:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1528 bytes --]

On Tue, 21 Sep 2010, Peter Münster wrote:

> On Tue, Sep 21 2010, Johan Sandblom wrote:
>
>> Is there a way to instruct
>> \typefile to ignore the last four lines of the outputfile? I assume
>> defining an alternative command which does just that is not too
>> difficult, but sadly beyond me.
>
> It seems, that it's not possible at the moment. There is a tracker item
> for this feature: http://tracker.luatex.org/view.php?id=475

Not hard to do, just no interface. We can change buffers.range so that it 
accepts {1,-4} to mean from first to last-4 lines, and then just set

   \typefile[lines={1,-4}]{filename}

In any case, it is easy to define a lua function that does this.

\startluacode

function buffers.stripfromend(name, count)
     local str = buffers.loaddata(name)
     if str and str~= "" then
         local lines = str:splitlines()
         local line, n, action = 0, 0, buffers.typeline
         local first, last, m = buffers.strip(lines)
         last = last - count
         m    = m - count
         for i=first,last do
             n, line = action(lines[i], n, m, line)
         end
     end
end
\stopluacode

\unprotect
\def\strippedtyping#1#2% count file
   {\begingroup
    \tttf
    \let\obs\specialobeyedspace
    \ctxlua{buffers.stripfromend(\!!bs#2\!!es, #1)}
    \endgraf
    \endgroup}
\protect

\starttext

\strippedtyping{4}{filename}

\stoptext

To use this with t-filter, you can just say

    readcommand=\strippedtyping{4},


Aditya

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-21 20:18         ` Aditya Mahajan
@ 2010-09-21 20:37           ` Johan Sandblom
  2010-09-21 20:45           ` Hans Hagen
  1 sibling, 0 replies; 11+ messages in thread
From: Johan Sandblom @ 2010-09-21 20:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Perfect, thank you.

Johan

2010/9/21 Aditya Mahajan <adityam@umich.edu>:
> On Tue, 21 Sep 2010, Peter Münster wrote:
>
>> On Tue, Sep 21 2010, Johan Sandblom wrote:
>>
>>> Is there a way to instruct
>>> \typefile to ignore the last four lines of the outputfile? I assume
>>> defining an alternative command which does just that is not too
>>> difficult, but sadly beyond me.
>>
>> It seems, that it's not possible at the moment. There is a tracker item
>> for this feature: http://tracker.luatex.org/view.php?id=475
>
> Not hard to do, just no interface. We can change buffers.range so that it
> accepts {1,-4} to mean from first to last-4 lines, and then just set
>
>  \typefile[lines={1,-4}]{filename}
>
> In any case, it is easy to define a lua function that does this.
>
> \startluacode
>
> function buffers.stripfromend(name, count)
>    local str = buffers.loaddata(name)
>    if str and str~= "" then
>        local lines = str:splitlines()
>        local line, n, action = 0, 0, buffers.typeline
>        local first, last, m = buffers.strip(lines)
>        last = last - count
>        m    = m - count
>        for i=first,last do
>            n, line = action(lines[i], n, m, line)
>        end
>    end
> end
> \stopluacode
>
> \unprotect
> \def\strippedtyping#1#2% count file
>  {\begingroup
>   \tttf
>   \let\obs\specialobeyedspace
>   \ctxlua{buffers.stripfromend(\!!bs#2\!!es, #1)}
>   \endgraf
>   \endgroup}
> \protect
>
> \starttext
>
> \strippedtyping{4}{filename}
>
> \stoptext
>
> To use this with t-filter, you can just say
>
>   readcommand=\strippedtyping{4},
>
>
> Aditya
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>
>



-- 
Johan Sandblom, MD PhD
m +46735521477  Sweden
"What is wanted is not the will to believe, but the
will to find out, which is the exact opposite"
- Bertrand Russell
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Removing banner from mtxrun output
  2010-09-21 20:18         ` Aditya Mahajan
  2010-09-21 20:37           ` Johan Sandblom
@ 2010-09-21 20:45           ` Hans Hagen
  1 sibling, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2010-09-21 20:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 21-9-2010 10:18, Aditya Mahajan wrote:

> Not hard to do, just no interface. We can change buffers.range so that
> it accepts {1,-4} to mean from first to last-4 lines, and then just set

indeed a few lines patch ... will be in next beta

\starttext

\starttyping
line 1 !
line 2 !
line 3 !
line 4 !
line 5 !
line 6 !
\stoptyping

\starttyping[range={2,3}]
line 1
line 2 !
line 3 !
line 4
line 5
line 6
\stoptyping

\starttyping[range={2,-3}]
line 1
line 2 !
line 3 !
line 4
line 5
line 6
\stoptyping

\stoptext


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-09-21 20:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-20  8:26 Removing banner from mtxrun output Johan Sandblom
2010-09-20  8:44 ` luigi scarso
2010-09-20  9:23   ` Aditya Mahajan
2010-09-20 20:56   ` Johan Sandblom
2010-09-21 18:44     ` Johan Sandblom
2010-09-21 19:28       ` Peter Münster
2010-09-21 20:18         ` Aditya Mahajan
2010-09-21 20:37           ` Johan Sandblom
2010-09-21 20:45           ` Hans Hagen
2010-09-20  9:17 ` Aditya Mahajan
2010-09-20 20:02   ` Johan Sandblom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).