I'd like to run an interactive binary using system()
within R.
By interactive, suppose I wanted to run the python command-line interpreter from within R (who knows why, but in any case...).
When I run R from the command line (ie Rterm), I can start up the python interpreter like so:
> system('python.exe')
Python 2.7.2 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # I can now type in python commands and basically use the python
# interpreter until I've had enough.
# Now I'll exit the python interpreter:
>>> exit()
> # Presto, I'm back to the R prompt!
The point is, I can interact with the python interpreter from R just as if I'd started the interpreter from the command line in the first place, and I can exit it when I'm done to get back to the R prompt.
Now, let's try the same with the R GUI:
> system('python.exe')
Python 2.7.2 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
> # eh? it exitted?
This just runs python.exe (displaying that welcome message), but then quits straight away - I can't interact with the python interpreter.
My question is -- is there any way (in R GUI, ie the windows one) to run that interpreter and interact with it in the same way that works from any command-line version of R?
(FYI - when I first started learning how to write R packages, my goal as my first ever R package was just to be able to play nethack in R. Worked beautifully (I use linux & hence the command-line R), except when I took it to the windows RGui it would start the process but not be interactive, effectively locking up R until I forcibly ended the NetHack.exe process).
I worked it out - had to read the help file under Windows (turns out the unix & windows ?system
differ):
Do not try to run console applications that require user input from
Rgui
settingintern=TRUE
orshow.output.on.console=TRUE
. They will not work.
So looks like the best I'll get (from Rgui anyhow) is a new window being launched:
system('NetHack.exe',invisible=FALSE,wait=FALSE)
I'll add a if ( .Platform$GUI == "Rgui" )
check for this and set the parameters appropriately.
(Huzzah, onwards the quest of the NetHackR!)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.