[Rd] certain pipe() use cases not working in r-devel

Jennifer Bryan jenny@|@bry@n @end|ng |rom gm@||@com
Wed Feb 14 23:43:12 CET 2024


Hello,

I've noticed a specific type of pipe() usage that works in released R, but
not in r-devel.

In 4.3.2 on macOS, I can write to a connection returned by pipe(), i.e.
"hello, world" prints here:

> R.version.string
[1] "R version 4.3.2 (2023-10-31)"
> con <- pipe("cat")
> writeLines("hello, world", con)
hello, world

But in r-devel on macOS, this is silent no-op, i.e. "hello, world" does not
print:

> R.version.string
[1] "R Under development (unstable) (2024-02-13 r85895)"
> con <- pipe("cat")
> writeLines("hello, world", con)

My colleague Lionel Henry confirms he sees the same results on linux.
This particular example with cat doesn't work on Windows, so I don't have
any useful observations for that OS.

You might say this is a weird example or use case. The actual usage where I
discovered this is the way folks read/write the clipboard on macOS using
pbcopy/pbpaste (and, in very similar ways, on linux using xsel or xclip).
This is mentioned in the "Clipboard" section of the connections help topic.

In 4.3.2 on macOS, I can successfully roundtrip with the clipboard:

> pb_write <- pipe("pbcopy")
> writeChar("hello clipboard!", pb_write, eos = NULL)
> pb_read <- pipe("pbpaste")
> readChar(pb_read, 16)
[1] "hello clipboard!"

In r-devel, it appears that the write operation silently does nothing:

> pb_write <- pipe("pbcopy")
> writeChar("hello clipboard!", pb_write, eos = NULL)
> pb_read <- pipe("pbpaste")
> readChar(pb_read, 16)
character(0)

If the clipboard is populated through other means, I can
use readChar(pipe("pbpaste"), ...) to read the clipboard even in r-devel.
So this seems to be specific to writing to the connection.

Is this change in behaviour intentional and will it be present in the next
release of R? FWIW, I did a crude search of the source of all CRAN packages
and there are quite a few currently using pipe() for clipboard access on
*nix.

-- Jenny

	[[alternative HTML version deleted]]



More information about the R-devel mailing list