Rscript

0th

Percentile

Scripting Front-End for R

This is an alternative front end for use in #! scripts and other scripting applications.

Keywords
utilities
Usage
Rscript [options] [-e expr [-e expr2 ...] | file] [args]
Arguments
options
a list of options, all beginning with --. These can be any of the options of the standard Rfront-end, and also those described in the details.
expr, expr2
Rexpression(s), properly quoted.
file
the name of a file containing Rcommands. - indicates stdin.
args
arguments to be passed to the script in file.
Details

Rscript --help gives details of usage, and Rscript --version gives the version of Rscript.

Other invocations invoke the Rfront-end with selected options. This front-end is convenient for writing #! scripts since it is an executable and takes file directly as an argument. Options are always supplied: these imply . (The standard Windows command line has no concept of #! scripts, but Cygwin shells do.)

Either one or more options or file should be supplied. When using options be aware of the quoting rules in the shell used: see the examples.

Additional options accepted (before file or args) are [object Object],[object Object]

Spaces are allowed in expression and file (but will need to be protected from the shell in use, if any, for example by enclosing the argument in quotes).

#ifdef unix Normally the version of Ris determined at installation, but this can be overridden by setting the environment variable RHOME. #endif #ifdef windows The Rfiles are found from the location of the Rscript.exe executable. If this is copied elsewhere, the environment variable RHOME should be set to the top directory of the Rinstallation.

Unlike Unix-alikes, this links directly to R.dll rather than running a separate process. #endif

stdin() refers to the input file, and file("stdin") to the stdin file stream of the process.

Note

Rscript is only supported on systems with the execv system call.

Aliases
  • Rscript
Examples
library(utils) #ifdef unix Rscript -e 'date()' -e 'format(Sys.time(), "%a %b %d %X %Y")' #endif #ifdef windows # Note that Rscript is not by default in the PATH on Windows, so # either put it there or use an explicit path to Rscript. # at the standard Windows command line Rscript -e "date()" -e "format(Sys.time(), \"%a %b %d %X %Y\")" # in other shells, e.g. bash or tcsh, prefer Rscript -e 'date()' -e 'format(Sys.time(), "%a %b %d %X %Y")' #endif ## example #! script for a Unix-alike #! /path/to/Rscript --vanilla --default-packages=utils args <- commandArgs(TRUE) res <- try(install.packages(args)) if(inherits(res, "try-error")) q(status=1) else q()
Documentation reproduced from package utils, version 3.3, License: Part of R 3.3

Community examples

Looks like there are no examples yet.