[R] Flushing the R output buffer.

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Wed Oct 30 17:16:49 CET 2002

On Wed, 30 Oct 2002, Richard wrote:

> flusHi,


> I am connecting R to a PHP web script.
> The first effort attempted to use a named pipe
> but gave up on that because PHP could not read
> any data from the named pipe.
> I changed to using a temp file but it also has problems.
> It appears that the file to which R's output is redirected
> is not recieving any output until the pipe connection form PHP
> is closed. I think this means that R is buffering its output
> and there appears to be no flush function.

Redirected output is normally buffered: it's an issue for your OS's
runtime system.  R is just a C program.

> I would like to use a sequence like:
> open pipe to R and incommand redirect R outout to file/fifo
> open file
> send R command
> read response from file
> close file
> open file
> send R command
> read response from file
> close file
> .
> .
> close pipe
> I checked the archives and there a function
> flush.console() was mentioned -- I looked for this in
> the docs but could not find it. The function does not appear
> to affect flushing of the R output to the file.

Well, it is documented for the Windows GUI, where it does work.
How can a function you can't find affect R when you can't run it?

> This is a RedHat Linsux 7.3 on x86 install

Try using connections, in particular a fifo and play with blocking.  It
would not be too hard to implement a flush() function if you want one
(there is internal support for it in the design of connections): if
you do write one, please contribute it.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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