Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing Interactive R session

Tags:

r

How does one run an R script forcing the session to be interactive. The docs in ?interative say that --ess and --interactive control this, but I don't see any effect.

Windows:

C:\Program Files\R\R-3.0.1\bin>R  -e "interactive()" --ess -s
[1] FALSE

Mac:

$ R -e "interactive()" --interactive -s
[1] FALSE

Any thoughts?

EDIT: I suppose on can hack the base namespace which may work for some things (like install.packages). But this is a poor excuse for a solution...

$ R -e "unlockBinding('interactive',as.environment('package:base'));assign('interactive',function() TRUE,envir=as.environment('package:base'));base::interactive()" --interactive -s
[1] TRUE
like image 505
Ian Fellows Avatar asked Jun 26 '13 18:06

Ian Fellows


People also ask

How do I run R in interactive mode?

You can run R interactively or in batch mode. e.g. type in R from the shell. The window that appears is called the R console. Any command you type into the prompt is interpreted by the R kernel.

What is an interactive R session?

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.


1 Answers

That had come up with our beloved littler alternative to Rscript, and I then added a toggle:

edd@max:~$ r -p -e 'interactive()'
[1] FALSE
edd@max:~$ r -i -p -e 'interactive()'
[1] TRUE
edd@max:~$ 

It may well be that R when invoked as you do always sets it to false.

like image 50
Dirk Eddelbuettel Avatar answered Sep 30 '22 17:09

Dirk Eddelbuettel