[Rd] Reading exit code of pipe()

Jeroen Ooms jeroen.ooms at stat.ucla.edu
Thu May 14 19:07:30 CEST 2015


On Thu, May 14, 2015 at 7:30 AM, William Dunlap <wdunlap at tibco.com> wrote:
> The difference in the return value of close(pipeConnectionObject) seems to depend on whether the pipe connection was opened via the pipe() or open() functions (close() returns NULL) or via something like readLines() or scan() (close() returns status integer).

Hmm interesting. It doesn't help me though; the connection has to be
explicitly opened to support streaming otherwise it keeps running the
command over and over again:

 con <- pipe("ls -ltr /")
 readLines(con, n = 3)
 readLines(con, n = 3)
 readLines(con, n = 3)
 isOpen(con)

Under the hood, R distinguishes "closing" and "destroying" the
connection. The R function close actually means destroy. It seems like
the pipe exit code is only properly returned if the connection was
already closed but not destroyed by the time close() was called.



More information about the R-devel mailing list