11

ファイル接続を作成してpath <- file("C:/test.txt")おり、接続に関連付けられたオブジェクトを印刷すると、接続の「属性」が表示されます。

> path
  description         class          mode          text        opened 
"C:/test.txt"        "file"           "r"        "text"      "closed" 
     can read     can write 
        "yes"         "yes" 

ただし、さまざまな属性値に実際にアクセスする方法がわかりません

これが私がこれまでに試したことです:

> 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

何か案は?

4

2 に答える 2

13

をざっと見る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"
于 2012-08-28T11:50:14.523 に答える
1

あなたが望むものに最も近いのは、summary()を使用することです。例えば:

summary(path)$mode
[1] "rt"

file.info()を使用するとエラーが発生します。これは、その関数がファイルへのパス、つまり「C:/test.txt」を引数として想定しているためです。

于 2012-08-28T11:51:13.670 に答える