[R] Flushing the R output buffer.

David B. Dahl dbdahl at stat.wisc.edu
Fri Nov 1 04:39:59 CET 2002


I run into this problem when trying to control R from a Java program.  
Hopefully my solution can help you.

After poking around the source code, I realized that when R starts up, it 
choose between interactive or non-interactive mode, based on whether there is 
a controlling TTY.  Specifically, line 237 of src/unix/system.c has the line 
"R_Interactive = isatty(0);"  My solution is to insert the following line 
immediately after line 237:
"if ( getenv("R_FORCE_INTERACTIVE") != NULL ) R_Interactive = TRUE;"
I then compile R.  (You implied that you were adverse to learning how to 
compile from source, but it really isn't hard.  See "R Installation and 
Administration" documentation from the R webpage.)
Then, within Java, I set the environment variable "R_FORCE_INTERACTIVE" to 
"true" and launch R.  I can then write commands to R and read the response, 
all without buffering or flushing issues.

I hope this helps.  I would be interest in knowing how well this works for you 
or what other solution you come up with.

- - David Dahl

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list