1R(1) User Commands R(1)
2
3
4
6 r - Provides hash-bang (#!) capability for R (www.r-project.org)
7
9 r [options] [-|file] [R arguments]
10
12 Launches GNU R to execute the specified file containing R commands, or
13 takes commands from stdin if '-' is used to denote stdin, using the
14 specified options. This makes it suitable to create R scripts via the
15 so-called shebang '#!/' line. The optional R arguments are stored in
16 the R vector argv.
17
19 -h, --help
20 Display a short help list.
21
22 --usage
23 Give a short usage message.
24
25 -V, --version
26 Show the version number.
27
28 -v, --vanilla
29 Pass the '--vanilla' option to R.
30
31 -t, --rtemp
32 Use a per-session temporary directory as R does.
33
34 -i, --interactive
35 Force 'interactive()' to evaluate to TRUE, whereas the default
36 is FALSE.
37
38 -q, --quick
39 Skip autoload (i.e. delayed assign) of default libraries.
40
41 -p, --verbose
42 Print the value of expressions to the console.
43
44 -l, --packages list
45 Load the R packages from the comma-separated 'list'.
46
47 -d, --datastdin
48 Evaluates 'X <- read.csv(file="stdin", stringsAsFactors=FALSE)'
49 to read a data set from stdin.
50
51 -L, --libpath dir
52 Add directory to library path via '.libPaths(dir)'.
53
54 -e, --eval expr
55 Evaluate 'expr' in R.
56
58 r can be used in command-line 'pipes' as well as in 'shebang'-style
59 scripts.
60
62 Piping R commands:
63
64 echo 'cat(pi^2,"\n")' | r
65
66 Equivalently, R commands can be given on the command-line:
67
68 r -e 'cat(pi^2, "\n")'
69
70 Alternatively, commands can be stored in a file, which in turn might
71 use R command 'readLines' to process stdin input:
72
73 $ cat examples/fsizes.r
74 fsizes <- as.integer(readLines())
75 print(summary(fsizes))
76 stem(fsizes)
77
78 which can be evaluated by r with the following command:
79
80 ls -l /boot | awk '!/^total/ {print $5}' | r examples/fsizes.r
81
82 The script file may contain a "shebang" line:
83
84 $ cat examples/install.r
85 #!/usr/bin/env r
86 # a simple example to install one or more packages
87 if (is.null(argv) | length(argv)<1) {
88 cat("Usage: installr.r pkg1 [pkg2 pkg3 ...]0)
89 q()
90 }
91 repos <- "http://cran.us.r-project.org"
92 lib.loc <- "/usr/local/lib/R/site-library"
93 install.packages(argv, lib.loc, repos, dependencies=TRUE)
94
95 and if it is executable, it can be called as:
96
97 examples/install.r "TeachingDemos"
98
99 See the examples directory in the sources for more.
100
102 The executable program is called r, but the project is called littler
103 to avoid confusion with the real GNU R.
104
106 The GNU R language is documented extensively at the R website
107 (http://www.r-project.org) and in several manuals available in html,
108 info and pdf.
109
111 Jeffrey Horner <jeff.horner@vanderbilt.edu>. Dirk Eddelbuettel
112 <edd@debian.org>.
113
114
115
116r September 2006 R(1)