[R] R equivalent of python module structure and functionality?

Tom Roche Tom_Roche at pobox.com
Wed Sep 12 04:35:46 CEST 2012


https://stat.ethz.ch/pipermail/r-help/2012-September/323551.html
>>> summary: how to structure an R file such that it can be both

>>> 1. used as a script via, e.g., (from OS commandline)

>>> $ Rscript foo.r bar=baz

>>> 2. imported and called as a function via, e.g. (from R commandline)

>>> > source('./foo.r')

or otherwise loaded, then called, e.g.

>>> > foo(bar='baz')

>>> ? I'm looking for the 'R equivalent' of how python supports this

https://stat.ethz.ch/pipermail/r-help/2012-September/323553.html
>> "littler provides hash-bang (i.e. script starting with #!/some/path)
>> capability for GNU R, as well as simple command-line and piping use.

Apparently so, but I don't see how that jointly satisfies the usecases
above. (Also, I don't see what littler provides that Rscript doesn't--
both do hash-bang--but that's probably orthogonal to this question.)

https://stat.ethz.ch/pipermail/r-help/2012-September/323554.html
> I also wanted to point Tom to CRAN packages
>     getopt
>     optparse
> written specifically to support command-line argument parsing with R

Thanks, but again, I'm not seeing how those solve the given problem(s).
Am I missing something?

TIA, Tom Roche <Tom_Roche at pobox.com>




More information about the R-help mailing list