`system ()` interactive.exe / binary from R / Rgui

I would like to run an interactive binary using system() inside R.

In interactive mode, suppose I wanted to run the python command line interpreter from R (who knows why, but anyway ...).

When I run R from the command line (i.e. Rterm), I can start the python interpreter as follows:

 > 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 thing is, I can interact with the python interpreter from R in the same way as if I started the interpreter from the command line first, and I can exit it when I finish, to return to the R prompt.

Now 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? 

It just launches the python.exe file (displays this welcome message), but then leaves immediately - I cannot interact with the python interpreter.

My question is: is there any way (in the R GUI, that is, in the windows one) to run this interpreter and interact with it in the same way that works from any version of the R command line?

(FYI - when I first started learning how to write R-packages, my goal as my first R-package was just to play nethack in R. It worked beautifully (I use Linux and therefore the R command line) unless I picked it up in Windows RGui, it will start the process, but will not be interactive, effectively blocking R until I have NetHack.exe).

+4
source share
1 answer

I worked on this - I had to read the help file for Windows (it turns out that unix and windows ?system are different):

Do not try to run console applications that require the user to Rgui intern=TRUE or show.output.on.console=TRUE from Rgui . They will not work.

So, it looks like the best I get (from Rgui anyway) is a new window launches:

 system('NetHack.exe',invisible=FALSE,wait=FALSE) 

I will add an if ( .Platform$GUI == "Rgui" ) check if ( .Platform$GUI == "Rgui" ) for this and configure the settings accordingly.

(Huzzah, go ahead NetHackR quest!)

+4
source

Source: https://habr.com/ru/post/1400327/


All Articles