I'm trying to call the load()
function on a socketConnection
. When I establish the connection (between two R processes), I check the socket info and I see this:
> s <- socketConnection(host = "localhost", 12345, server = FALSE, blocking=TRUE, open = "rb")
> s
description class mode text
"->localhost:12345" "sockconn" "rb" "binary"
opened can read can write
"opened" "yes" "yes"
The connection was opened successfully and it is readable (and in binary mode). If I now try to read from the socket, I get this:
> load(s)
Error in load(s) : connection not open for reading
Took me a while to figure out why I see the socket saying "can read=yes", while the error message is saying it is not readable. Turns out, the connection is being wrapped with a gzcon object when performing the load()
. If I wrap it myself, I see this:
> s
description class mode text
"->localhost:12345" "sockconn" "rb" "binary"
opened can read can write
"opened" "yes" "yes"
> z <- gzcon(s)
> z
description class
"gzcon(->localhost:12345)" "gzcon"
mode text
"rb" "binary"
opened can read
"opened" "no"
can write
"yes"
> s
description class
"gzcon(->localhost:12345)" "gzcon"
mode text
"rb" "binary"
opened can read
"opened" "no"
can write
"yes"
The gzcon converts the connection to unreadable. So my question is, how can I perform a load from a socket, or how I can force gzcon to keep the connection readable?