[Rd] pari/gp interface

Henrik Bengtsson hb at stat.berkeley.edu
Wed Jul 26 19:07:50 CEST 2006


On 7/25/06, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> The issue is that system() on Windows does not run a shell, so piping is
> not going to be available: used shell() instead.   Then the problem is
> that the shell available is OS-specific, and pretty minimal on Windows
> 95/98/ME.  If you can ignore those (and they are getting rarer), cmd.exe
> can be assumed for use of shell().
>
> echo is not a standard system command on Windows either, and in a shell
> does not do what it does on Unix.
>
> On Tue, 25 Jul 2006, Henrik Bengtsson wrote:
>
> > On 7/25/06, Robin Hankin <r.hankin at noc.soton.ac.uk> wrote:
> > > Hi
> > >
> > > I'm developing an R package that
> > > needs to execute some code written in pari/gp.
> > >
> > > I've used this before from an R package (elliptic) but the interface
> > > is very
> > > basic: the R function creates a string such as the following:
> > >
> > > string <- echo ' ellwp ([ 2+0*I , 0+2*I ], 1+0*I )' | gp -q
> > >
> > > And then
> > >
> > > system(string)
> > >
> > > returns the output from gp which then needs to be text processed
> > > (translating "I"
> > > to "i", etc).
> > >
> > > I don't think this approach would work under Windows.
> >
> > I know nothing about pari/gp, but I believe it does work on Windows
> > too.  There is system() command available on the Windows version too,
> > but with slightly different arguments (than on Linux say).
> >
> > Piping is available on Windows too, e.g. "dir | sort", although you
> > should be able to get around that by writing to file instead and using
> > ">" and "<".
>
> Did you try that?  dir is not an executable under Windows (a shell
> command), and it does not work even if you use an executable.  You do need
> to use shell()

Too quick there - I didn't do this using system() but from the Windows
command prompt;

> system("dir | sort")
Warning message:
dir not found

> shell("dir | sort")
              10 Dir(s)   4,458,024,960 bytes free
...
07/26/2006  09:56 AM    <DIR>          .
07/26/2006  09:56 AM    <DIR>          ..
07/26/2006  10:00 AM            15,055 .Rhistory

What I wanted to get through though is that it is possible to obtain
the same thing in Windows.  You might have to modify the code to be
sensitive to .Platform$OS.type.  When I do these kind of things I
often write a BAT script that I call using system("foo.bat").

/Henrik

>
> >
> > You should be careful if your 'string' gets really long.  Then it is
> > much better to have a BAT file (and an sh file on Linux) to run your
> > external calls, alternatively you call system() multiple times.
> > However, I would be suprised if 'ellwp' wouldn't accept files as input
> > too.
> >
> > /Henrik
> >
> > > Does anyone have any experience of calling pari/gp from R?
> > >
> > > Or any ideas for a more portable method than the one above?
> > >
> > >
> > >
> > >
> > > [
> > > PARI/GP is a widely used computer algebra system designed for fast
> > > computations
> > > in number theory.  It is freely available at
> > >
> > >   http://pari.math.u-bordeaux.fr/
> > > ]
> > >
> > >
> > > --
> > > Robin Hankin
> > > Uncertainty Analyst
> > > National Oceanography Centre, Southampton
> > > European Way, Southampton SO14 3ZH, UK
> > >   tel  023-8059-7743
> > >
> > > ______________________________________________
> > > R-devel at r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-devel
> > >
> > >
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
> >
>
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>



More information about the R-devel mailing list