我正在尝试load()
在socketConnection
. 当我建立连接(在两个 R 进程之间)时,我检查了套接字信息,我看到了:
> 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"
连接已成功打开并且它是可读的(并且在二进制模式下)。如果我现在尝试从套接字读取,我会得到:
> load(s)
Error in load(s) : connection not open for reading
我花了一段时间才弄清楚为什么我看到套接字说“可以读取=是”,而错误消息却说它不可读。事实证明,在执行load()
. 如果我自己包装它,我会看到:
> 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"
gzcon 将连接转换为不可读。所以我的问题是,如何从套接字执行加载,或者如何强制 gzcon 保持连接可读?