Scroll to navigation

R(1) User Commands R(1)


r - Provides hash-bang (#!) capability for R (


r [options] [-|file] [R arguments]


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.


Display a short help list.
Give a short usage message.
Show the version number.
Pass the '--vanilla' option to R.
Use a per-session temporary directory as R does.
Force 'interactive()' to evaluate to TRUE, whereas the default is FALSE.
Skip autoload (i.e. delayed assign) of default libraries.
Print the value of expressions to the console.
Load the R packages from the comma-separated 'list'.
Evaluates 'X <- read.csv(file="stdin", stringsAsFactors=FALSE)' to read a data set from stdin.
Add directory to library path via '.libPaths(dir)'.
Evaluate 'expr' in R.


r can be used in command-line 'pipes' as well as in 'shebang'-style scripts.


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())

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 ...]0)
repos <- ""
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.


The executable program is called r, but the project is called littler to avoid confusion with the real GNU R.


The GNU R language is documented extensively at the R website ( and in several manuals available in html, info and pdf.


Jeffrey Horner <>. Dirk Eddelbuettel <>.

September 2006 r