| 42333 |
ripley |
1 |
% File src/library/utils/man/Rscript.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 1995-2011 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 40361 |
ripley |
6 |
\name{Rscript}
|
| 56186 |
murdoch |
7 |
\alias{Rscript}
|
| 40361 |
ripley |
8 |
\title{Scripting Front-End for R}
|
|
|
9 |
\description{
|
| 49704 |
hornik |
10 |
This is an alternative front end for use in \samp{#!} scripts and
|
| 40361 |
ripley |
11 |
other scripting applications.
|
|
|
12 |
}
|
|
|
13 |
\usage{
|
| 40396 |
ripley |
14 |
\special{Rscript [options] [-e expression] file [args]}
|
| 40361 |
ripley |
15 |
}
|
|
|
16 |
\arguments{
|
| 49612 |
hornik |
17 |
\item{options}{A list of options beginning with \samp{--}. These can
|
| 40361 |
ripley |
18 |
be any of the options of the standard \R front-end, and also those
|
|
|
19 |
described in the details.}
|
| 40396 |
ripley |
20 |
\item{expression}{a \R expression.}
|
| 49704 |
hornik |
21 |
\item{file}{The name of a file containing \R commands. \samp{-}
|
| 40361 |
ripley |
22 |
indicates \file{stdin}.}
|
|
|
23 |
\item{args}{Arguments to be passed to the script in \code{file}.}
|
|
|
24 |
}
|
|
|
25 |
\details{
|
| 49704 |
hornik |
26 |
\command{Rscript --help} gives details of usage, and
|
|
|
27 |
\command{Rscript --version} gives the version of \command{Rscript}.
|
| 40361 |
ripley |
28 |
|
|
|
29 |
Other invocations invoke the \R front-end with selected options. This
|
| 49704 |
hornik |
30 |
front-end is convenient for writing \samp{#!} scripts since it is an
|
| 40361 |
ripley |
31 |
executable and takes \code{file} directly as an argument. Options
|
| 49704 |
hornik |
32 |
\option{--slave --no-restore} are always supplied: these imply
|
| 50567 |
ripley |
33 |
\option{--no-save}. (The standard Windows command line has no concept
|
|
|
34 |
of \samp{#!} scripts, but Cygwin shells do.)
|
| 40361 |
ripley |
35 |
|
| 40430 |
ripley |
36 |
\emph{Either} one or more \option{-e} options or \code{file} should
|
| 46718 |
ripley |
37 |
be supplied. When using \option{-e} options be aware of the quoting
|
|
|
38 |
rules in the shell used: see the examples.
|
| 40396 |
ripley |
39 |
|
|
|
40 |
Additional options accepted (before \code{file} or \code{args}) are
|
| 40361 |
ripley |
41 |
\describe{
|
| 49704 |
hornik |
42 |
\item{\option{--verbose}}{gives details of what \command{Rscript} is
|
| 40361 |
ripley |
43 |
doing. Also passed on to \R.}
|
| 49704 |
hornik |
44 |
\item{\option{--default-packages=list}}{where \code{list} is a
|
| 40361 |
ripley |
45 |
comma-separated list of package names or \code{NULL}. Sets the
|
| 47259 |
ripley |
46 |
environment variable \env{R_DEFAULT_PACKAGES} which determines the
|
| 49704 |
hornik |
47 |
packages loaded on startup. The default for \command{Rscript}
|
|
|
48 |
omits \pkg{methods} as it takes about 60\% of the startup time.
|
| 40481 |
ripley |
49 |
}
|
| 40361 |
ripley |
50 |
}
|
| 61433 |
ripley |
51 |
|
| 55931 |
ripley |
52 |
Spaces are allowed in \code{expression} and \code{file} (but will need
|
|
|
53 |
to be protected from the shell in use, if any, for example by
|
|
|
54 |
enclosing the argument in quotes).
|
| 61433 |
ripley |
55 |
|
| 40361 |
ripley |
56 |
#ifdef unix
|
|
|
57 |
Normally the version of \R is determined at installation, but this can
|
|
|
58 |
be overridden by setting the environment variable \env{RHOME}.
|
|
|
59 |
#endif
|
|
|
60 |
#ifdef windows
|
| 40373 |
ripley |
61 |
The \R files are found from the location of the \file{Rscript.exe}
|
|
|
62 |
executable. If this is copied elsewhere, the environment variable
|
|
|
63 |
\env{RHOME} should be set to the top directory of the \R installation.
|
| 61433 |
ripley |
64 |
|
| 40361 |
ripley |
65 |
Unlike Unix-alikes, this links directly to \file{R.dll} rather than
|
|
|
66 |
running a separate process.
|
|
|
67 |
#endif
|
| 40373 |
ripley |
68 |
|
|
|
69 |
\code{\link{stdin}()} refers to the input file, and
|
|
|
70 |
\code{\link{file}("stdin")} to the \code{stdin} file stream of the
|
|
|
71 |
process.
|
| 40361 |
ripley |
72 |
}
|
|
|
73 |
#ifdef unix
|
|
|
74 |
\note{
|
| 49704 |
hornik |
75 |
\command{Rscript} is only supported on systems with the \code{execv}
|
| 40361 |
ripley |
76 |
system call.
|
|
|
77 |
}
|
|
|
78 |
#endif
|
|
|
79 |
\examples{\dontrun{
|
| 46718 |
ripley |
80 |
#ifdef unix
|
| 41395 |
ripley |
81 |
Rscript -e 'date()' -e 'format(Sys.time(), "\%a \%b \%d \%X \%Y")'
|
| 46718 |
ripley |
82 |
#endif
|
|
|
83 |
#ifdef windows
|
|
|
84 |
# Note that Rscript is not by default in the PATH on Windows, so
|
|
|
85 |
# either put it there or use an explicit path to Rscript.
|
| 40396 |
ripley |
86 |
|
| 46718 |
ripley |
87 |
# at the standard Windows command line
|
|
|
88 |
Rscript -e "date()" -e "format(Sys.time(), \\"\%a \%b \%d \%X \%Y\\")"
|
|
|
89 |
# in other shells, e.g. bash or tcsh, prefer
|
|
|
90 |
Rscript -e 'date()' -e 'format(Sys.time(), "\%a \%b \%d \%X \%Y")'
|
|
|
91 |
#endif
|
| 40361 |
ripley |
92 |
|
| 46718 |
ripley |
93 |
## example #! script for a Unix-alike
|
|
|
94 |
|
| 40361 |
ripley |
95 |
#! /path/to/Rscript --vanilla --default-packages=utils
|
| 41395 |
ripley |
96 |
args <- commandArgs(TRUE)
|
| 40361 |
ripley |
97 |
res <- try(install.packages(args))
|
|
|
98 |
if(inherits(res, "try-error")) q(status=1) else q()
|
|
|
99 |
|
|
|
100 |
}}
|
|
|
101 |
\keyword{utilities}
|