interactive: Is R Running Interactively? (original) (raw)
interactive | R Documentation |
---|
Is R Running Interactively?
Description
Return TRUE
when R is being used interactively andFALSE
otherwise.
Usage
interactive()
Details
An interactive R session is one in which it is assumed that there is a human operator to interact with, so for example R can prompt for corrections to incorrect input or ask what to do next or if it is OK to move to the next plot.
GUI consoles will arrange to start R in an interactive session. WhenR is run in a terminal (via Rterm.exe
on Windows), it assumes that it is interactive if ‘stdin’ is connected to a (pseudo-)terminal and not if ‘stdin’ is redirected to a file or pipe. Command-line options --interactive (Unix) and--ess (Windows, Rterm.exe
) override the default assumption. (On a Unix-alike, whether the readline
command-line editor is used is not overridden by --interactive.)
Embedded uses of R can set a session to be interactive or not.
Internally, whether a session is interactive determines
- how some errors are handled and reported, e.g. see
stop
andoptions("showWarnCalls")
. - whether one of --save, --no-save or--vanilla is required, and if R ever asks whether to save the workspace.
- the choice of default graphics device launched when needed and by
dev.new
: seeoptions("device")
- whether graphics devices ever ask for confirmation of a new page.
In addition, R's own R code makes use of interactive()
: for example help
, debugger
andinstall.packages
do.
Note
This is a primitive function.
See Also
source
,.First
Examples
.First <- function() if(interactive()) x11()