Read Large CSV Files in R: Choosing a Method That Keeps Your Data Intact

A practical review of ways to read large CSV and TSV files in R, including fread, readr, arrow and duckdb, and how each affects types, encoding and memory.

What this review covers

Reading a large CSV file in R is a conversion step. Delimited text goes in, and a typed in-memory table or a queryable dataset comes out. The method you choose affects speed and memory use. It also decides how column types are guessed, how text encoding is handled, and whether values like ZIP codes or long ID numbers survive unchanged. This review compares the common approaches against those concerns. It does not report benchmark figures, because no measured test results were supplied. Speed comparisons depend heavily on your hardware, the file's structure and package versions, so test on a sample of your own data.

Is this approach suitable for my use?

For most large files that still fit comfortably in memory, data.table::fread or readr::read_csv is a reasonable default. Both are designed to be faster than base R's read.csv, and both detect or let you declare column types. The main tradeoff is memory. These functions load the full result into RAM, so a file close to or larger than your available memory needs a different approach.

If the file is larger than memory, or you only need a filtered or summarized subset, a query-based tool is usually a better fit. The arrow package and duckdb can scan the file, apply filters or aggregations, and return only the result. The tradeoff is an extra dependency and a slightly different workflow, since you build a query first and collect results afterward.

Base read.csv remains a sensible choice for smaller files, for scripts that must avoid package dependencies, or for teaching. Its performance improves noticeably when you supply colClasses and nrows, but it is generally not the first choice for very large inputs.

Approach | Best suited to | Main tradeoff
data.table::fread | Large files that fit in memory; auto-detecting delimiters | Returns a data.table, whose syntax differs from data frames and tibbles, though it can be converted
readr::read_csv / read_tsv | Tidyverse workflows; explicit, readable type specifications | Type guessing uses a limited sample of rows by default
readr::read_csv_chunked | Processing a file piece by piece when the full table is not needed at once | You must write a callback that handles each chunk
arrow::open_dataset / read_csv_arrow | Files larger than memory; filtering before loading; converting to Parquet | Additional package; queries must be collected to become a regular data frame
duckdb | SQL-style filtering and aggregation directly over CSV files | Additional package and a database connection to manage
utils::read.csv | Small files; dependency-free scripts | Slower on large inputs unless types and row counts are supplied

What does reading the file actually change?

The CSV file on disk is not modified. What changes is the representation in R. Each field starts as text and is converted to a type such as integer, double, logical, date or character. Most surprises come from that conversion, not from the delimiter parsing.

  • Type inference: readr guesses column types from a sample of rows (by default up to the first 1,000). If a column looks numeric early but contains text later, parsing problems are reported and the affected values become NA. Raising guess_max or declaring col_types avoids this.
  • Leading zeros: values such as ZIP codes, product codes or phone numbers can lose leading zeros if read as numbers. Declare these columns as character.
  • Large integers: IDs beyond the precision of a double can be silently rounded. fread reads such columns as 64-bit integers via the bit64 package by default. Elsewhere, reading them as character is the safest option.
  • Dates and times: automatic date parsing depends on the format and the reader. Declaring a format or parsing explicitly after import keeps behavior predictable.
  • Missing values: each reader has defaults for which strings count as missing, such as empty fields or NA. Check whether your file uses other markers.
  • Decimal and grouping marks: files that use a comma as the decimal separator need a matching locale or the semicolon-delimited variants, such as readr::read_csv2.

Selecting fewer columns is the most direct way to reduce memory use and load time. fread has select, readr has col_select, and arrow and duckdb only read the columns a query references.

# Fits in memory: declare types and read only needed columns
library(data.table)
dt <- fread("big.csv",
            select = c("id", "zip", "amount", "date"),
            colClasses = list(character = c("id", "zip")))

# readr equivalent with an explicit specification
library(readr)
df <- read_csv("big.csv",
               col_select = c(id, zip, amount, date),
               col_types = cols(id = col_character(),
                                zip = col_character(),
                                amount = col_double(),
                                date = col_date()))
problems(df)  # review any parsing issues
# Larger than memory: filter before loading
library(arrow)
library(dplyr)
ds <- open_dataset("big.csv", format = "csv")
result <- ds |>
  filter(amount > 100) |>
  select(id, amount) |>
  collect()

# Or with duckdb and SQL
library(DBI)
con <- dbConnect(duckdb::duckdb())
result <- dbGetQuery(con,
  "SELECT id, SUM(amount) AS total
   FROM read_csv_auto('big.csv')
   GROUP BY id")
dbDisconnect(con, shutdown = TRUE)

TSV and other delimited files follow the same principles. fread detects the separator automatically. readr offers read_tsv and read_delim, and arrow and duckdb accept a delimiter option. For files you reread often, converting them once to a columnar format such as Parquet with arrow is a common way to speed up later loads. It does produce a binary file that plain-text tools cannot open.

Will the data remain readable and usable afterward?

Encoding is the main compatibility risk. readr assumes UTF-8 unless you set a locale encoding, and fread has an encoding argument. If a file was exported in a legacy encoding such as Latin-1 or Windows-1252, accented characters can appear garbled until you specify the correct one. Spot-check text columns that contain names, addresses or non-English words after import.

Writing data back out raises the same issue in reverse. fwrite and write_csv produce UTF-8 text. Some spreadsheet programs handle UTF-8 CSV files more reliably when they begin with a byte order mark, which readr's write_excel_csv adds. How a particular spreadsheet version behaves was not tested here, so confirm with the program your recipients actually use.

Types do not travel with a CSV file. A column you carefully read as character, such as ZIP codes, can be reinterpreted as numbers by whoever opens the exported file next. When exact values matter, share a short data dictionary along with the file, or use a typed format such as Parquet if the recipient's tools support it.

Plain CSV is preferable when the data must be opened by people or tools you do not control, inspected in a text editor, or archived for long-term readability. It is also accessible to screen readers and simple tools in a way binary formats are not. Columnar formats are preferable when speed and preserved types matter more than universal readability.

Gaps in this review

No benchmark data, file-size thresholds or hardware-specific measurements were available, so this review makes no claims about which reader is fastest in absolute terms. Function arguments and defaults can change between package releases, so check the current documentation for the versions you have installed before relying on a specific default.