title: Partition a large file into small files in R
body: <p>I need to break a large file (14 gigabytes) into smaller files. The format of this file is txt, the tab is ";" and I know it has 70 columns (string, double). I would like to read 1million and save them in different files, file1, file2 ... fileN.</p>
  
  <p>after the help of @MKR </p>
  
  <p>but process was very slow, I tried using fread, but it was not possible.</p>
  
  <p>How can I optimize this code?</p>
  
  <p><strong>NEW CODE</strong> </p>
  
  <pre><code>chunkSize &lt;- 10000
  conex &lt;- file(description = db, open = "r")
  data &lt;- read.table(conex, nrows = chunkSize, header=T, fill=TRUE, sep =";")
  
  index &lt;- 0
  counter &lt;- 0
  total &lt;- 0
  chunkSize &lt;- 500000 
  conex &lt;- file(description=db,open="r")   
  dataChunk &lt;- read.table(conex, nrows=chunkSize, header=T, fill=TRUE,sep=";")
  
  repeat {
  dataChunk &lt;- read.table(conex, nrows=chunkSize, header=FALSE, fill = TRUE, sep=";", col.names=db_colnames)
  total &lt;- total + sum(dataChunk$total)
  counter &lt;- counter + nrow(dataChunk)
  write.table(dataChunk, file = paste0("MY_FILE_new",index),sep=";", row.names = FALSE)
  
    if (nrow(dataChunk) != chunkSize){
      print('linesok')
      break}
      index &lt;- index + 1
    print(paste('lines', index * chunkSize))
  }
  </code></pre>