[R] scripts with littler

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jan 8 16:03:52 CET 2007


Looks like it will be possible to write scripts with R 2.5.0 using the
new -f flag and file("stdin").  From https://svn.r-project.org/R/trunk/NEWS :

    o	Command-line R (and Rterm.exe under Windows) accepts the options
	'-f filename', '--file=filename' and '-e expression' to follow
	other script interpreters.  These imply --no-save unless
	--save is specified.

[..]

    o	file("stdin") is now recognized, and refers to the process's
	'stdin' file stream whereas stdin() refers to the console.
	These may differ, for example for a GUI console, an embedded
	application of R or if --file= has been used.



On 1/8/07, John Lawrence Aspden <news at aspden.com> wrote:
> Thanks, that's a really neat mechanism, ( I especially like the note to vim,
> which will save all my scripts having to end .R )
>
> Is there any way to get at the command line and stdio though?
>
> With littler I can do things like:
>
> #!/usr/bin/env r
>
> print(argv)
> t=read.table(file=stdin())
>
> so that I can write unix-style filters.
>
> Cheers, John.
>
>
>
> François Pinard wrote:
>
>
> > I usually do something like:
> >
> >
> > #!/bin/sh
> > R --slave --vanilla <<EOF
> >
> >    R script goes here...
> >
> > EOF
> >
> > # vim: ft=r
> >
> >
> > If you need to search special places for packages, you may tweak
> > exported environment variables between the first and second line.
>
>
> --
> Contractor in Cambridge UK -- http://www.aspden.com
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list