[R] textConnections so slow!

Gabor Grothendieck ggrothendieck at myway.com
Mon Nov 10 22:11:39 CET 2003


 --- On Mon 11/10, Mathieu Drapeau < mathieu.drapeau at bioneq.qc.ca > wrote:
> Is it normal that it takes a very long time to generate a 
> connection object on a big character vector?

If the reason you need a text connection is that you are locating
your data via a tag like this:

   lines <- readLines( "input.txt" )    # lines is a vector of lines
   g <- grep( "start", lines )   # position of tag
   mydata <- read.table( textConnection(lines), skip=g[1], head=TRUE )

then you could simply read your data twice like this:

   lines <- readLines( "input.txt" )    # lines is a vector of lines
   g <- grep( "start", lines )   # position of tag
   mydata <- read.table( "input.txt", skip=g[1], head=TRUE )




More information about the R-help mailing list