Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the attributes of a file connection created via file()

I'm creating a file connection via path <- file("C:/test.txt") and when printing the object associated to the connection I can see the connection's "attributes":

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

However, I can't seem to figure out how to actually access the various attribute values

Here's what I tried so far:

> 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

Any ideas?

like image 433
Rappster Avatar asked Aug 28 '12 11:08

Rappster


1 Answers

A quick look at base:::print.connection will show that you want 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"
like image 152
Josh O'Brien Avatar answered Nov 10 '22 08:11

Josh O'Brien