[NTG-context] Removing banner from mtxrun output

2010-09-20 Thread Johan Sandblom
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


m-r.tex
Description: TeX document
___
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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-20 Thread luigi scarso
On Mon, Sep 20, 2010 at 10:26 AM, Johan Sandblom  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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-20 Thread Aditya Mahajan

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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-20 Thread Aditya Mahajan

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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-20 Thread Johan Sandblom
2010/9/20 Aditya Mahajan :
> 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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-20 Thread Johan Sandblom
> 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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-21 Thread Johan Sandblom
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 :
>> 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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-21 Thread Peter Münster
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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-21 Thread Aditya Mahajan

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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-21 Thread Johan Sandblom
Perfect, thank you.

Johan

2010/9/21 Aditya Mahajan :
> 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
___


Re: [NTG-context] Removing banner from mtxrun output

2010-09-21 Thread Hans Hagen

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
___