What ? ===== littler - Provides hash-bang (#!) capability for R (www.r-project.org) Why ? ==== GNU R, a language and environment for statistical computing and graphics, provides a wonderful system for 'programming with data' as well as interactive exploratory analysis, often involving graphs. Sometimes, however, simple scripts are desired. While GNU R can be used in batch mode, and while so-called 'here' documents can be crafted, a long-standing need for a scripting front-end has often been expressed by the R Community. littler (pronounced 'little R' and written 'r') aims to fill this need. It can be used directly on the command-line just like, say, bc(1): $ echo 'cat(pi^2,"\n")' | r 9.869604 Equivalently, commands that are to be evaluated can be given on the command-line $ r -e 'cat(pi^2, "\n")' 9.869604 But unlike bc(1), GNU R has a vast number of statistical functions. For example, we can quickly compute a summary() and show a stem-and-leaf plot for file sizes in a given directory via $ ls -l /boot | awk '!/^total/ {print $5}' | \ r -e 'fsizes <- as.integer(readLines()); print(summary(fsizes)); stem(fsizes)' Min. 1st Qu. Median Mean 3rd Qu. Max. 13 512 110100 486900 768400 4735000 Loading required package: grDevices The decimal point is 6 digit(s) to the right of the | 0 | 00000000000000000011112223 0 | 5557778899 1 | 112233 1 | 5 2 | 2 | 3 | 3 | 4 | 4 | 7 And, last but not least, this (somewhat unwieldy) expression can be stored in a helper script: $ cat examples/fsizes.r #!/usr/bin/env r fsizes <- as.integer(readLines()) print(summary(fsizes)) stem(fsizes) (where calling /usr/bin/env is a trick from Python which allows one to forget whether r is installed in /usr/bin/r, /usr/local/bin/r, ~/bin/r, ...) A few examples are provided in the source directories examples/ and tests/. Where ? ====== littler can either be downloaded from http://biostat.mc.vanderbilt.edu/LittleR accessed by anonymous SVN: $ svn co http://littler.googlecode.com/svn/trunk/ littler or (soon !) be gotten from Debian mirrors via $ agt-get install littler littler is known to build and run on Linux and OS X. Who ? ==== Copyright (C) 2006 Jeffrey Horner and Dirk Eddelbuettel littler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Comments are welcome, as are are suggestions, bug fixes, or patches. - Jeffrey Horner <jeff.horner at vanderbilt.edu> - Dirk Eddelbuettel <edd at debian.org>
Any plans for Windows? On 9/26/06, Jeffrey Horner <jeff.horner at vanderbilt.edu> wrote:> > What ? > =====> > littler - Provides hash-bang (#!) capability for R (www.r-project.org) > > > Why ? > ====> > GNU R, a language and environment for statistical computing and > graphics, provides a wonderful system for 'programming with data' > as well as interactive exploratory analysis, often involving graphs. > > Sometimes, however, simple scripts are desired. While GNU R can > be used in batch mode, and while so-called 'here' documents can be > crafted, a long-standing need for a scripting front-end has often > been expressed by the R Community. > > littler (pronounced 'little R' and written 'r') aims to fill > this need. > > It can be used directly on the command-line just like, say, bc(1): > > > $ echo 'cat(pi^2,"\n")' | r > 9.869604 > > Equivalently, commands that are to be evaluated can be given on > the command-line > > $ r -e 'cat(pi^2, "\n")' > 9.869604 > > But unlike bc(1), GNU R has a vast number of statistical > functions. For example, we can quickly compute a summary() and show > a stem-and-leaf plot for file sizes in a given directory via > > $ ls -l /boot | awk '!/^total/ {print $5}' | \ > r -e 'fsizes <- as.integer(readLines()); > print(summary(fsizes)); stem(fsizes)' > Min. 1st Qu. Median Mean 3rd Qu. Max. > 13 512 110100 486900 768400 4735000 > Loading required package: grDevices > > The decimal point is 6 digit(s) to the right of the | > > 0 | 00000000000000000011112223 > 0 | 5557778899 > 1 | 112233 > 1 | 5 > 2 | > 2 | > 3 | > 3 | > 4 | > 4 | 7 > > > And, last but not least, this (somewhat unwieldy) expression can > be stored in a helper script: > > $ cat examples/fsizes.r > #!/usr/bin/env r > > fsizes <- as.integer(readLines()) > print(summary(fsizes)) > stem(fsizes) > > (where calling /usr/bin/env is a trick from Python which allows one > to forget whether r is installed in /usr/bin/r, /usr/local/bin/r, > ~/bin/r, ...) > > A few examples are provided in the source directories examples/ > and tests/. > > Where ? > ======> > littler can either be downloaded from > > http://biostat.mc.vanderbilt.edu/LittleR > > accessed by anonymous SVN: > > $ svn co http://littler.googlecode.com/svn/trunk/ littler > > or (soon !) be gotten from Debian mirrors via > > $ agt-get install littler > > littler is known to build and run on Linux and OS X. > > > Who ? > ====> > Copyright (C) 2006 Jeffrey Horner and Dirk Eddelbuettel > > littler is free software; you can redistribute it and/or modify it > under the terms of the GNU General Public License as published by > the Free Software Foundation; either version 2 of the License, or > (at your option) any later version. > > This program is distributed in the hope that it will be useful, > but WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > General Public License for more details. > > You should have received a copy of the GNU General Public > License along with this program; if not, write to the Free > Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, > MA 02111-1307 USA > > Comments are welcome, as are are suggestions, bug fixes, or patches. > > > - Jeffrey Horner <jeff.horner at vanderbilt.edu> > - Dirk Eddelbuettel <edd at debian.org> > > ______________________________________________ > 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. >
Wow, looks neat. OS X users will be unhappy with your naming choice as the default filesystem there is not case-sensitive :-( IOW, r and R do the same thing. I would expect it to otherwise work on OS X so a change of some sort might be worthwhile. + seth
On 9/26/2006 1:04 PM, Jeffrey Horner wrote:> What ? > =====> > littler - Provides hash-bang (#!) capability for R (www.r-project.org) > > > Why ? > ====> > GNU R, a language and environment for statistical computing and > graphics, provides a wonderful system for 'programming with data' > as well as interactive exploratory analysis, often involving graphs. > > Sometimes, however, simple scripts are desired. While GNU R can > be used in batch mode, and while so-called 'here' documents can be > crafted, a long-standing need for a scripting front-end has often > been expressed by the R Community. > > littler (pronounced 'little R' and written 'r') aims to fill > this need. > > It can be used directly on the command-line just like, say, bc(1): > > > $ echo 'cat(pi^2,"\n")' | r > 9.869604Is there a technical reason that this couldn't work by modifying the script that invokes R? That would avoid the r/R clash on MacOSX and Windows. In Windows R is R.exe, not a script, so some adjustment would be needed there, but that shouldn't be difficult. Duncan Murdoch> > Equivalently, commands that are to be evaluated can be given on > the command-line > > $ r -e 'cat(pi^2, "\n")' > 9.869604 > > But unlike bc(1), GNU R has a vast number of statistical > functions. For example, we can quickly compute a summary() and show > a stem-and-leaf plot for file sizes in a given directory via > > $ ls -l /boot | awk '!/^total/ {print $5}' | \ > r -e 'fsizes <- as.integer(readLines()); > print(summary(fsizes)); stem(fsizes)' > Min. 1st Qu. Median Mean 3rd Qu. Max. > 13 512 110100 486900 768400 4735000 > Loading required package: grDevices > > The decimal point is 6 digit(s) to the right of the | > > 0 | 00000000000000000011112223 > 0 | 5557778899 > 1 | 112233 > 1 | 5 > 2 | > 2 | > 3 | > 3 | > 4 | > 4 | 7 > > > And, last but not least, this (somewhat unwieldy) expression can > be stored in a helper script: > > $ cat examples/fsizes.r > #!/usr/bin/env r > > fsizes <- as.integer(readLines()) > print(summary(fsizes)) > stem(fsizes) > > (where calling /usr/bin/env is a trick from Python which allows one > to forget whether r is installed in /usr/bin/r, /usr/local/bin/r, > ~/bin/r, ...) > > A few examples are provided in the source directories examples/ > and tests/. > > Where ? > ======> > littler can either be downloaded from > > http://biostat.mc.vanderbilt.edu/LittleR > > accessed by anonymous SVN: > > $ svn co http://littler.googlecode.com/svn/trunk/ littler > > or (soon !) be gotten from Debian mirrors via > > $ agt-get install littler > > littler is known to build and run on Linux and OS X. > > > Who ? > ====> > Copyright (C) 2006 Jeffrey Horner and Dirk Eddelbuettel > > littler is free software; you can redistribute it and/or modify it > under the terms of the GNU General Public License as published by > the Free Software Foundation; either version 2 of the License, or > (at your option) any later version. > > This program is distributed in the hope that it will be useful, > but WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > General Public License for more details. > > You should have received a copy of the GNU General Public > License along with this program; if not, write to the Free > Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, > MA 02111-1307 USA > > Comments are welcome, as are are suggestions, bug fixes, or patches. > > > - Jeffrey Horner <jeff.horner at vanderbilt.edu> > - Dirk Eddelbuettel <edd at debian.org> > > ______________________________________________ > 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.
I like this plan and have now played with the concept. I did the following on Windows in cygwin. It would also work in Unix, and I think could be tickled to work on the standard MS cmd line in Windows. It would certainly work on Windows with a Windows-native port of the basic unix utilities. echo 'options(echo=FALSE);cat(pi^2,"\n")' | Rterm --no-save This produces an output file, that normally shows up in the *shell* buffer, but could be redirected. The obvious place to redirect it to is awk with a script to filter out everything above the echo of the options() line. The only change to R needed to remove the need for an awk script is to suppress the display of the copyright message and startup information. I suppose that could be done with a new --suppress-startup-info argument to Rterm. The other optimizations that Jeffrey and Dirk have, such as suppressing the loading of many of the standard packages, would also need to be done. Very good work and concept. Rich