R(1)
okay so picture this: you wanna write R scripts with a shebang line and just... run them like a normal person. That's literally what r is for. This is the R(1) page, from the User Commands section, and it's about to be your new bestie. π
β¨ NAME β¨
r β it gives you hash-bang (#!) capability for R, which lives over at www.r-project.org. Slay. π
πΈ SYNOPSIS πΈ
r [options] [-|file] [R arguments]
π¦ DESCRIPTION π¦
It launches GNU R to execute the file you handed it (the one full of R commands), or it takes commands from stdin if you use - to denote stdin β using whatever options you specified. Which means it's perfect for making R scripts via the so-called shebang #!/ line. π The optional R arguments get stored in the R vector argv. Obsessed, honestly.
π OPTIONS π
-h,--helpβ displays a short help list.--usageβ gives a short usage message.-V,--versionβ shows the version number. periodt.-v,--vanillaβ passes the--vanillaoption to R.-t,--rtempβ uses a per-session temporary directory, the way R does.-i,--interactiveβ forcesinteractive()to evaluate to TRUE, whereas the default is FALSE, fyi.-q,--quickβ skips autoload (i.e. delayed assign) of default libraries.-p,--verboseβ prints the value of expressions to the console.-l,--packageslist β loads the R packages from the comma-separatedlist.-d,--datastdinβ evaluatesX <- read.csv(file="stdin", stringsAsFactors=FALSE)to read a data set from stdin.-L,--libpathdir β adds a directory to the library path via.libPaths(dir).-e,--evalexpr β evaluatesexprin R.
π USAGE π
r can be used in command-line pipes and in shebang-style scripts. Both. Iconic behaviour honestly. π
π§ ENVIRONMENT π§
When it's used with a shebang line in a script file, the path to that file is made available to R in the LITTLER_SCRIPT_PATH environment variable. π
π₯ 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 the 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 ...]0)
q()
}
repos <- "http://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, bestie. π«Ά
π NOTE π
The executable program is called r, but the project is called littler β specifically to avoid confusion with the real GNU R. Not me getting confused either, no cap. π
π SEE ALSO π
The GNU R language is documented extensively at the R website (http://www.r-project.org) and in several manuals available in html, info and pdf. Go read, you'll eat it up. π
π«Ά AUTHORS π«Ά
Jeffrey Horner <jeff.horner@vanderbilt.edu>. Dirk Eddelbuettel <edd@debian.org>.
and that's the whole vibe check, bestie β this page is r, dated September 2006, and it lives in the R(1) manual. That's the source, the version and the date all in one cute little sign-off. bye ily πβ¨π
π¦ where this page comes from
- debian trixie: r-cran-littler 0.3.21-1
- epel 10: R-littler 0.3.23-1.el10_3 Β· GPL-2.0-or-later
- epel 9: R-littler 0.3.23-1.el9 Β· GPL-2.0-or-later
- fedora 44: R-littler 0.3.21-4.fc44 Β· GPL-2.0-or-later
- fedora 44: R-littler 0.3.23-1.fc44 Β· GPL-2.0-or-later
- ubuntu questing: r-cran-littler 0.3.21-1
- ubuntu resolute: r-cran-littler 0.3.22-1
- ubuntu stonking: r-cran-littler 0.3.23-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms