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 )
  read.csv(con,header=F)
  close(con)

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)
  close(con)

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)
  close(con)

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

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?


WangSong

                                          
        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to