[R] one way to write scripts in R

Jason E. Aten j.e.aten at gmail.com
Mon Mar 29 18:31:36 CEST 2010


Thanks Gabor. I didn't realize you could.  Here is the scriptdemo.rsh  file
as a text attachment, in case the line wraps made it hard to read/use.

- Jason

On Mon, Mar 29, 2010 at 11:19 AM, Gabor Grothendieck <
ggrothendieck at gmail.com> wrote:

> Thanks.
>
> You might want to repost it as a text attachment since many of the
> lines wrapped around.
>
> Another more permanent possibility would be to put it on the R wiki at
> http://rwiki.sciviews.org/doku.php
>
> Note that the gsubfn package has a facility for quasi-perl type string
> interpolation as well. Just preface any function with fn$ and the
> facility is applied to the arguments of the function (subject to
> certain heuristics which determine which args to apply it to).
>
> > library(gsubfn)
> > today <- format(Sys.Date())
> > show <- list()
> > show$syntax <- 43
> > Sys.setenv(AN_ENV_VAR="greetings (I'm an env var!)")
> >
> > fn$cat('Getting `Sys.getenv("AN_ENV_VAR")` from the environment, on
> $today,
> + `show$syntax` is also possible.\n')
> Getting greetings (I'm an env var!) from the environment, on 2010-03-29,
> 43 is also possible.
>
>
>
> On Mon, Mar 29, 2010 at 11:41 AM, Jason E. Aten <j.e.aten at gmail.com>
> wrote:
> > Dear R users,
> >
> > A colleague of mine asked me how to write a script (an executable text
> file
> > containing R code) in R. After I showed
> > him, he said that after extensive searching of the R archives, he had not
> > found anything like these techniques.
> >
> > He suggested that I share these methods to enable others to leverage R as
> a
> > better alternative to bash/perl scripts.
> >
> > So in the interest of giving back to the R community, and with all
> humility,
> > I offer the
> > following small demonstration of one method for creating scripts of R
> code
> > that are
> > executable from the (at least Linux) command line.
> >
> > I don't make any warrantees that this will work for you, but if it helps
> > somebody at least
> > get starting utilizing R effectively in scripts, then great!
> >
> > Best regards,
> >
> > Jason
> >
> > --
> > Jason E. Aten, Ph.D.
> >
> >
> > # file: scriptdemo.rsh
> >
>


More information about the R-help mailing list