read-write: Read and write data to process

Description Usage Arguments Details Examples

Description

Read and write data to process

Usage

1
2
3
4
5
write_stdin(stream, data, send_endl = TRUE, send_eof = FALSE)

read_stdout(stream, timeout = 1)

read_stderr(stream, timeout = 1, bufsz = 1024, max_reads = 1024)

Arguments

stream

a pstream object

data

a vector of values

send_endl

if true, write return to stream

send_eof

if true, write EOF to stream

timeout

number of second to atempt reading

Details

Because reading from the pipe stream is non-blocking, there is no method to determine whether the process has written anything to its standard out or standard error. As a result, read_stdout and read_stderr may return empty strings indicating the process has not generated any output. These two read functions take a timeout parameter that sets the amount of time in seconds to attempt reading. If any output is available for consumption during this period, then these functions will continue to read output until all available output is consumed or the number of read exceeds the max_reads parameter. This output is then returned. A slight pause is necessary between attempts to consume output from the process. This delay is controlled by the compile-time parameter TICK_DELAY, which is in units of miliseconds. Ten miliseconds appears to be sufficient to avoid starvation of the input buffer. A longer delay will be less likely to return partial output and will be more CPU efficient. A shorter delay will lead to less latency.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
x = pstream("R")
read_stderr(x)

x = pstream("R", "--vanilla")
read_stdout(x)
write_stdin(x, "R.Version()[[1]]")
read_stdout(x)
write_stdin(x, "q()")
x = pstream("R", "--vanilla --slave")
system.time(read_stdout(x, 1))
system.time(read_stdout(x, 2))
system.time(read_stdout(x, 3))
write_stdin(x, "R.Version()[[1]]")
system.time(read_stdout(x, 100))
pstream_close(x)

thk686/pipestreamr documentation built on May 31, 2019, 10:43 a.m.