r (1)
Leading comments
hey, Emacs: 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 f...
NAME
r - Provides hash-bang (#!) capability for R (www.r-project.org)SYNOPSIS
r [options] [-|file] [R arguments]DESCRIPTION
Launches GNU R to execute the specified file containing R commands, or takes commands from stdin if '-' is used to denote stdin, using the specified options. This makes it suitable to create R scripts via the so-called shebang '#!/' line. The optional R arguments are stored in the R vector argv.OPTIONS
- -h, --help
- Display a short help list.
- --usage
- Give a short usage message.
- -V, --version
- Show the version number.
- -v, --vanilla
- Pass the '--vanilla' option to R.
- -t, --rtemp
- Use a per-session temporary directory as R does.
- -i, --interactive
- Force 'interactive()' to evaluate to TRUE, whereas the default is FALSE.
- -q, --quick
- Skip autoload (i.e. delayed assign) of default libraries.
- -p, --verbose
- Print the value of expressions to the console.
- -l, --packages list
- Load the R packages from the comma-separated 'list'.
- -d, --datastdin
- Evaluates 'X <- read.csv(file="stdin", stringsAsFactors=FALSE)' to read a data set from stdin.
- -L, --libpath dir
- Add directory to library path via '.libPaths(dir)'.
- -e, --eval expr
- Evaluate 'expr' in R.
USAGE
r can be used in command-line 'pipes' as well as in 'shebang'-style scripts.EXAMPLES
Piping R commands:echo 'cat(pi^2,"\n")' | r
Equivalently, R commands can be given on the command-line:
r -e 'cat(pi^2, "\n")'
Alternatively, commands can be stored in a file, which in turn might use R command 'readLines' to process stdin input:
$ cat examples/fsizes.r
fsizes <- as.integer(readLines())
print(summary(fsizes))
stem(fsizes)
which can be evaluated by r with the following command:
ls -l /boot | awk '!/^total/ {print $5}' | r examples/fsizes.r
The script file may contain a "shebang" line:
$ cat examples/install.r
#!/usr/bin/env r
# a simple example to install one or more packages
if (is.null(argv) | length(argv)<1) {
cat("Usage: installr.r pkg1 [pkg2 pkg3 ...])
q()
}
repos <- "cran.us.r-project.org"
lib.loc <- "/usr/local/lib/R/site-library"
install.packages(argv, lib.loc, repos, dependencies=TRUE)
and if it is executable, it can be called as:
examples/install.r "TeachingDemos"
See the examples directory in the sources for more.