[Rd] Feature request: copy attributes in gzcon

Jeroen Ooms jeroenooms at gmail.com
Tue Mar 3 19:43:20 CET 2015

The `gzcon` function both modifies and copies a connection object:

  # compressed text
  con1 <- url("http://www.stats.ox.ac.uk/pub/datasets/csb/ch12.dat.gz")
  con2 <- gzcon(con1)

  # almost indistinguishable
  identical(summary(con2), summary(con1))

  # both support gzip
  readLines(con1, n = 3)
  readLines(con2, n = 3)

  # opening one opens both

In the example, `con1` and `con2` are two different objects
interfacing the same connection. It might seem as if gzcon has simply
returned the modified connection object, but the documentation
explains that it in fact creates a copy referencing the same
connection but with a "modified internal structure".

It is unclear to me how `con1` is different from `con2`, but given
that they represent one and the same connection, would it be possible
to make gzcon copy over attributes from the input connection to the
output object?

This would allow custom connection implementations such as the curl
package to use attributes for storing additional metadata about
connection. Currently those attributes get dropped after calling gzcon
on the connection:

  con <- curl("http://www.stats.ox.ac.uk/pub/datasets/csb/ch12.dat.gz")
  attr(con, "foo") <- "bar"

  con <- gzcon(con)
  attr(con, "foo")

It would be very helpful if gzcon would instead copy attributes onto
the output object, such that any potential meta-data about the
connection as stored in attributes gets retained.

More information about the R-devel mailing list