Skip to content

Instantly share code, notes, and snippets.

View clap-hands-in-the-r's full-sized avatar

Mael clap-hands-in-the-r

View GitHub Profile
@peterhurford
peterhurford / num_rows_csv.R
Last active November 5, 2024 08:13
What's the fastest way to determine the number of rows of a CSV in R?
# What's the fastest way to determine the number of rows of a CSV in R?
# ...Reading the entire CSV to only get the dimensions is likely too slow. Is there a faster way?
# Benchmarks done on a EC2 r3.8xlarge
# Cowritten with Abel Castillo <github.com/abelcastilloavant>
m <- 1000000
d <- data.frame(id = seq(m), a = rnorm(m), b = runif(m))
dim(d)
# [1] 1000000 3
pryr::object_size(d)