vroom_lines() is similar to readLines(), however it reads the lines lazily like vroom(), so operations like length(), head(), tail() and sample() can be done much more efficiently without reading all the data into R.

vroom_lines(file, n_max = Inf, skip = 0, altrep_opts = "chr",
  num_threads = vroom_threads(), progress = vroom_progress())



path to a local file.


Maximum number of records to read.


Number of lines to skip before reading data.


Control which column types use Altrep representations, either a character vector of types, TRUE or FALSE. See vroom_altrep_opts() for for full details.


Number of threads to use when reading and materializing vectors.


Display a progress bar? By default it will only display in an interactive session and not while knitting a document. The display is updated every 50,000 values and will only display if estimated reading time is 5 seconds or more. The automatic progress bar can be disabled by setting option readr.show_progress to FALSE.


lines <- vroom_lines(vroom_example("mtcars.csv")) length(lines)
#> [1] 33
head(lines, n = 2)
#> [1] "model,mpg,cyl,disp,hp,drat,wt,qsec,vs,am,gear,carb" #> [2] "Mazda RX4,21,6,160,110,3.9,2.62,16.46,0,1,4,4"
tail(lines, n = 2)
#> [1] "Maserati Bora,15,8,301,335,3.54,3.57,14.6,0,1,5,8" #> [2] "Volvo 142E,21.4,4,121,109,4.11,2.78,18.6,1,1,4,2"
sample(lines, size = 2)
#> [1] "Merc 230,22.8,4,140.8,95,3.92,3.15,22.9,1,0,4,2" #> [2] "Maserati Bora,15,8,301,335,3.54,3.57,14.6,0,1,5,8"