访问通过file()创建的文件连接的属性

Rap*_*ter 10 connection-string r file file-connection

我正在通过创建文件连接path <- file("C:/test.txt"),当打印与连接关联的对象时,我可以看到连接的"属性":

> path
  description         class          mode          text        opened 
"C:/test.txt"        "file"           "r"        "text"      "closed" 
     can read     can write 
        "yes"         "yes" 
Run Code Online (Sandbox Code Playgroud)

但是,我似乎无法弄清楚如何实际访问各种属性值

这是我到目前为止所尝试的:

> attributes(path)
$class
[1] "file"       "connection"

$conn_id
<pointer: 0x0000004b>

> path$description
Error in path$description : $ operator is invalid for atomic vectors

> path["description"]
[1] NA

> file.info(path)
Error in file.info(path) : invalid filename argument
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Jos*_*ien 11

快速查看base:::print.connection将显示您想要的内容summary(path).

summary(path)
$description
[1] "C:/test.txt"

$class
[1] "file"

$mode
[1] "r"

$text
[1] "text"

$opened
[1] "closed"

$`can read`
[1] "yes"

$`can write`
[1] "yes"
Run Code Online (Sandbox Code Playgroud)