简体   繁体   中英

R interactive and batch mode and the heIp browser

When running R in 'batch mode', the interactive flag is set to false, which prevents any sort of user prompts that would interrupt the process in the context of an embedded/batch setting. See:

R -e 'interactive()'

Some holds when using Rscript . The flag can also manually be set by using the interactivity package. To test, we can try:

R -e 'install.packages("anything")

Assuming no CRAN mirror has been set yet, install.packages will not show some interactive mirror picker, but instead throw an error and exit.

However, I noticed that the help or ? command will still work. For example, the command below will show the help browser, and it does not continue until I press q.

R -e 'help(lm); 1+2'

However, when sending the output to a file, it does not show the interactive prompt and just dumps the complete help document in the output:

R -e 'help(lm); 1+2' > output.txt

I'm a bit confused now about what is really going on when using help . Why do you get the interactive help browser even when R is running in batch mode? Is this a feature of R , or from the Debian/Ubuntu front-end? Is there a risk of R becoming unresponsive when the help function is called inside ie Rserve, RInside, JRI, etc, due to R waiting for using input?

help actually spawns a new process, pager, which is like "less":

> help(lm); 1+2
[1]+  Stopped                 R -e 'help(lm); 1+2'
$ ps
  PID TTY          TIME CMD
27735 pts/6    00:00:00 bash
31607 pts/6    00:00:00 R
31615 pts/6    00:00:00 sh
31616 pts/6    00:00:00 pager
31617 pts/6    00:00:00 ps

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM