How to Read a CSV File in R
· 1 min read · Updated March 14, 2026 · beginner
r csv data-import readr data.table
Reading CSV files is one of the most common data import tasks in R.
With readr
The tidyverse readr package provides read_csv():
library(readr)
df <- read_csv("data.csv")
# # A tibble: 100 x 5
From a URL:
df <- read_csv("https://example.com/data.csv")
Specify column types:
df <- read_csv("data.csv", col_types = cols(
id = col_integer(),
name = col_character()
))
With base R
df <- read.csv("data.csv", stringsAsFactors = FALSE)
For large files, use data.table::fread():
library(data.table)
df <- fread("data.csv")
# id name value
# 1: 1 Alice 10.5
See Also
- data.frame — Base R data frame
- tibble — Tidyverse tibble