How to Read CSV Files in R with readr and Base R
To read CSV files in R, the read_csv() function from readr is the modern default — it returns a tibble and prints column type information so you can verify the import at a glance. For simple use, one line is all it takes.
library(readr)
df <- read_csv("data.csv")
For base R, read.csv() returns a standard data frame. Pass stringsAsFactors = FALSE to keep character columns as strings, and header = TRUE (the default) when the first row contains column names.
df <- read.csv("data.csv", stringsAsFactors = FALSE)
When your CSV uses a semicolon delimiter, common in European locales, use read_csv2() from readr or pass sep = ";" to read.csv(). For files without a header row, use col_names = FALSE in readr or header = FALSE in base R. For large files above a few hundred megabytes, data.table::fread() reads 5–10× faster than either alternative. Use col_types in readr to specify column types upfront, avoiding the slower column-type guessing step on huge imports.
See also
- data.frame, Base R data frame
- tibble, Tidyverse tibble
- How to Read an Excel File in R, Related data import