| 42333 |
ripley |
1 |
% File src/library/utils/man/Rscript.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 81943 |
smeyer |
3 |
% Copyright 1995-2022 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{
|
| 81943 |
smeyer |
14 |
\special{Rscript [options] file [args]}
|
|
|
15 |
\special{Rscript [options] -e expr [-e expr2 ...] [args]}
|
| 40361 |
ripley |
16 |
}
|
|
|
17 |
\arguments{
|
| 64434 |
maechler |
18 |
\item{options}{a list of options, all beginning with \samp{--}. These
|
|
|
19 |
can be any of the options of the standard \R front-end, and also those
|
| 40361 |
ripley |
20 |
described in the details.}
|
| 64434 |
maechler |
21 |
\item{expr, expr2}{\R expression(s), properly quoted.}
|
|
|
22 |
\item{file}{the name of a file containing \R commands. \samp{-}
|
| 40361 |
ripley |
23 |
indicates \file{stdin}.}
|
| 80667 |
kalibera |
24 |
\item{args}{arguments to be passed to the script in \code{file} or
|
|
|
25 |
expressions supplied via \option{-e}.}
|
| 40361 |
ripley |
26 |
}
|
|
|
27 |
\details{
|
| 49704 |
hornik |
28 |
\command{Rscript --help} gives details of usage, and
|
|
|
29 |
\command{Rscript --version} gives the version of \command{Rscript}.
|
| 40361 |
ripley |
30 |
|
|
|
31 |
Other invocations invoke the \R front-end with selected options. This
|
| 49704 |
hornik |
32 |
front-end is convenient for writing \samp{#!} scripts since it is an
|
| 40361 |
ripley |
33 |
executable and takes \code{file} directly as an argument. Options
|
| 77228 |
maechler |
34 |
\option{--no-echo --no-restore} are always supplied: these imply
|
| 72557 |
kalibera |
35 |
\option{--no-save}. Arguments that contain spaces cannot be specified
|
|
|
36 |
directly on the \samp{#!} line, because spaces and tabs are interpreted as
|
|
|
37 |
delimiters and there is no way to protect them from this interpretation on
|
|
|
38 |
the \samp{#!} line. (The standard Windows command line has no concept
|
| 85953 |
hornik |
39 |
of \samp{#!} scripts, but \I{Cygwin} shells do.)
|
| 40361 |
ripley |
40 |
|
| 40430 |
ripley |
41 |
\emph{Either} one or more \option{-e} options or \code{file} should
|
| 46718 |
ripley |
42 |
be supplied. When using \option{-e} options be aware of the quoting
|
|
|
43 |
rules in the shell used: see the examples.
|
| 40396 |
ripley |
44 |
|
| 81170 |
kalibera |
45 |
The prescribed order of arguments is important: e.g. \option{--verbose}
|
|
|
46 |
specified after \option{-e} will be part of \code{args} and passed to the
|
|
|
47 |
expression; the same will happen to \option{-e} specified after
|
|
|
48 |
\code{file}.
|
|
|
49 |
|
|
|
50 |
Additional options accepted as part of \code{options} (before \code{file}
|
|
|
51 |
or \option{-e}) are
|
| 40361 |
ripley |
52 |
\describe{
|
| 49704 |
hornik |
53 |
\item{\option{--verbose}}{gives details of what \command{Rscript} is
|
| 81170 |
kalibera |
54 |
doing.}
|
| 49704 |
hornik |
55 |
\item{\option{--default-packages=list}}{where \code{list} is a
|
| 40361 |
ripley |
56 |
comma-separated list of package names or \code{NULL}. Sets the
|
| 47259 |
ripley |
57 |
environment variable \env{R_DEFAULT_PACKAGES} which determines the
|
| 74084 |
luke |
58 |
packages loaded on startup.
|
| 40481 |
ripley |
59 |
}
|
| 40361 |
ripley |
60 |
}
|
| 61433 |
ripley |
61 |
|
| 81943 |
smeyer |
62 |
Spaces are allowed in \code{expr} and \code{file} (but will need
|
| 55931 |
ripley |
63 |
to be protected from the shell in use, if any, for example by
|
|
|
64 |
enclosing the argument in quotes).
|
| 61433 |
ripley |
65 |
|
| 74084 |
luke |
66 |
If \option{--default-packages} is not used, then \command{Rscript}
|
|
|
67 |
checks the environment variable \env{R_SCRIPT_DEFAULT_PACKAGES}. If
|
|
|
68 |
this is set, then it takes precedence over \env{R_DEFAULT_PACKAGES}.
|
|
|
69 |
|
| 40361 |
ripley |
70 |
#ifdef unix
|
|
|
71 |
Normally the version of \R is determined at installation, but this can
|
|
|
72 |
be overridden by setting the environment variable \env{RHOME}.
|
|
|
73 |
#endif
|
|
|
74 |
#ifdef windows
|
| 40373 |
ripley |
75 |
The \R files are found from the location of the \file{Rscript.exe}
|
|
|
76 |
executable. If this is copied elsewhere, the environment variable
|
|
|
77 |
\env{RHOME} should be set to the top directory of the \R installation.
|
| 61433 |
ripley |
78 |
|
| 40361 |
ripley |
79 |
Unlike Unix-alikes, this links directly to \file{R.dll} rather than
|
|
|
80 |
running a separate process.
|
|
|
81 |
#endif
|
| 40373 |
ripley |
82 |
|
|
|
83 |
\code{\link{stdin}()} refers to the input file, and
|
|
|
84 |
\code{\link{file}("stdin")} to the \code{stdin} file stream of the
|
|
|
85 |
process.
|
| 40361 |
ripley |
86 |
}
|
|
|
87 |
#ifdef unix
|
|
|
88 |
\note{
|
| 49704 |
hornik |
89 |
\command{Rscript} is only supported on systems with the \code{execv}
|
| 40361 |
ripley |
90 |
system call.
|
|
|
91 |
}
|
|
|
92 |
#endif
|
|
|
93 |
\examples{\dontrun{
|
| 46718 |
ripley |
94 |
#ifdef unix
|
| 41395 |
ripley |
95 |
Rscript -e 'date()' -e 'format(Sys.time(), "\%a \%b \%d \%X \%Y")'
|
| 46718 |
ripley |
96 |
#endif
|
|
|
97 |
#ifdef windows
|
|
|
98 |
# Note that Rscript is not by default in the PATH on Windows, so
|
|
|
99 |
# either put it there or use an explicit path to Rscript.
|
| 40396 |
ripley |
100 |
|
| 46718 |
ripley |
101 |
# at the standard Windows command line
|
|
|
102 |
Rscript -e "date()" -e "format(Sys.time(), \\"\%a \%b \%d \%X \%Y\\")"
|
|
|
103 |
# in other shells, e.g. bash or tcsh, prefer
|
|
|
104 |
Rscript -e 'date()' -e 'format(Sys.time(), "\%a \%b \%d \%X \%Y")'
|
|
|
105 |
#endif
|
| 40361 |
ripley |
106 |
|
| 72093 |
maechler |
107 |
# Get the same initial packages in the same order as default R:
|
|
|
108 |
Rscript --default-packages=methods,datasets,utils,grDevices,graphics,stats -e 'sessionInfo()'
|
|
|
109 |
|
| 46718 |
ripley |
110 |
## example #! script for a Unix-alike
|
| 81170 |
kalibera |
111 |
## (arguments given on the #! line end up as [options] to Rscript, while
|
|
|
112 |
## arguments passed to the #! script end up as [args], so available to
|
|
|
113 |
## commandArgs())
|
| 40361 |
ripley |
114 |
#! /path/to/Rscript --vanilla --default-packages=utils
|
| 41395 |
ripley |
115 |
args <- commandArgs(TRUE)
|
| 40361 |
ripley |
116 |
res <- try(install.packages(args))
|
|
|
117 |
if(inherits(res, "try-error")) q(status=1) else q()
|
|
|
118 |
|
|
|
119 |
}}
|
|
|
120 |
\keyword{utilities}
|