[Rd] RFC: "loop connections"

Martin Maechler maechler at stat.math.ethz.ch
Sat Aug 27 12:18:16 CEST 2005

>>>>> "David" == David Hinds <dhinds at sonic.net>
>>>>>     on Mon, 22 Aug 2005 23:34:15 +0000 (UTC) writes:

    David> I've just implemented a generalization of R's text connections, to
    David> also support reading/writing raw binary data.  There is very little
    David> new code to speak of.  For input connections, I wrote code to populate
    David> the old text connection buffer from a raw vector, and provided a new
    David> raw_read() method.  For output connections, I wrote a raw_write() to
    David> append to a raw vector.  On input, the mode (text or binary) is
    David> determined by the data type of the input object; on output, I use the
    David> requested output mode (i.e. "w" / "wb").  For example:

    > con <- loopConnection("r", "wb")
    > a <- c(10,100,1000)
    > writeBin(a, con, size=4)
    > r
     [1] 00 00 20 41 00 00 c8 42 00 00 7a 44
    > close(con)
    > con <- loopConnection(r)
    > readBin(con, "double", n=3, size=4)
     [1]   10  100 1000
    > close(con)

    David> I think "loop connection" is a better name for this
    David> sort of connection than "text connection" was even
    David> for the old version; that confuses the mode of the
    David> connection (text vs binary) with the mechanism (file,
    David> socket, etc).


In the mean time, I think it has become clear that
"loopconnection" isn't necessarily a better name, and that
textConnection() has been there in "the S litterature" for a
good reason and for quite a while.
Let's forget about the naming and the exact UI for the moment.

I think the main point of David's proposal is still worth
consideration:  One way to see text connections is as a way to
treat some kind of R objects as "generalized files" i.e., connections.
And AFAICS David proposes to enlarge the kind of R objects that
can be dealt with as connections 
  from  {"character"} 
  to    {"character", "raw"} 
something which has some appeal to me.
IIUC, Brian Ripley is doubting the potential use for the
proposed generalization, whereas David makes a point of someone
else (the 'caTools' author) having written raw2bin / bin2raw function
for a related use case.

Maybe you can elaborate on the above a bit, David?
In any case, as you might have guessed by now, R-core would have
been more positive to a proposal to generalize current
textConnection() - fully back-compatibly - rather than renaming
it first.

Best regards,

More information about the R-devel mailing list