Skip to content
Prev 302212 / 398503 Next

embedding data frame in R code?

No you do not want to close all connections.  You should close each
connection that you open, but not others (they may be used by other
functions like sink() or capture.output()).  Use something like:

   readTableFromText <-function (text, ...) {
       tc <- textConnection(text, open = "r")
       on.exit(close(tc))
       read.table(tc, ...)
   }

as in

   > readTableFromText(c("10 ant", "20 bear", "30 cougar"), row.names=NULL)
     V1     V2
   1 10    ant
   2 20   bear
  3 30 cougar
  > showConnections() # no open connections
        description class mode text isopen can read can write
  >

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com