R(1)

πŸ“¦
version 0.3.23 Β· 2 versions
, in debian trixie, epel 10, epel 9, fedora 44, ubuntu questing, ubuntu resolute, ubuntu stonking

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 --vanilla option to R.
  • -t, --rtemp β€” uses a per-session temporary directory, the way R does.
  • -i, --interactive β€” forces interactive() 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, --packages list β€” loads 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 β€” adds a directory to the library path via .libPaths(dir).
  • -e, --eval expr β€” evaluates expr in 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 πŸ’–βœ¨πŸŽ€