[Rd] about textConnection

From: WANGSONG <mr.wangsong_at_hotmail.com>
Date: Thu, 10 Mar 2011 10:20:05 +0000

I need read a table in a string with special format. I used read.csv and textConnection function. But i am confuse about textConnection by follow code.

case A: It is OK£¡

  str0 <- '{"abc",{"def","X,1&Y,2&Z,3"}}'
  str1 <- strsplit(str0,'"')[[1]][6]
  str2 <- gsub("&","\n", str1)
  con  <- textConnection( str2 )



case B: It is NOK!
  con <- textConnection( gsub("&","\n",(strsplit('{"abc",{"def","X,1&Y,2&Z,3"}}','"')[[1]][6])) ) # Error in here   read.csv(con,header=F)

case C: It is OK!
  str0 <- '{"abc",{"def","X,1&Y,2&Z,3"}}'   con <- textConnection( gsub("&","\n", (strsplit(str0,'"')[[1]][6])) )   read.csv(con,header=F)


case D: It is OK!
  str2 <- gsub("&","\n", strsplit('{"abc",{"def","X,1&Y,2&Z,3"}}','"')[[1]][6])   con <- textConnection( str2 )


Except case B, textConnection report "invalid 'description' argument", in other case, textConnection is OK.

I don't known, what is different£¿ I report it as [Bug 14527], But the Answer is :
> your usage is incorrect.
> object: character. A description of the connection. For an input this is an R character vector object ...

> and you used an expression. Some expressions work, but only simple ones (and none are guaranteed to).

I read the help carefully, but i don't known which usage is incorrect.

Would you help me?


        [[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 10 Mar 2011 - 12:25:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Mar 2011 - 13:50:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive