Skip to content
Prev 239060 / 398500 Next

How long does skipping in read.table take

On Sat, Oct 23, 2010 at 10:07 AM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
The SQL statement does not know anything about R variables. You would
need something like this:
[1] "select from file limit 10, 9"
Also if you just want to read it in as chunks reading from a
connection in R would be sufficient:

k <- 5000 # no of rows per chunk
first <- TRUE
con <- file('myfile.csv', "r")
repeat {

   # skip header
   if (first) hdgs <- readLines(con, 1)
   first <- FALSE

   x <- readLines(con, k)
   if (length(x) == 0) break
   DF <- read.csv(textConnection(x), header = FALSE)

   # process chunk -- we just print last row here
   print(tail(DF, 1))

}
close(con)