Skip to contents

Estimate the size of a dataframe saved as a CSV file.

Usage

csv_size(x, frac = 0.05, format = TRUE)

Arguments

x

A data.frame that would be written to disk as a CSV.

frac

A numeric value between 0 and 1. The fractional size of x used for estimation of complete CSV size on disk.

format

TRUE or FALSE. If TRUE, automatically choose nice unit (megabytes, gigabytes, etc) for file size. If FALSE, file size in bytes.

Value

If format=FALSE, a numeric vector. If format=TRUE, a character vector.

Examples


#----------------------------------------------------------------------------
# csv_size() examples
#----------------------------------------------------------------------------
library(bkmisc)

# a data.frame with 50 columns and 100,000 rows of all numeric values
tmp <- data.frame(replicate(50, rnorm(10^5)))
csv_size(x = tmp, frac = 0.1, format = TRUE)
#> [1] "87.3 Mb"
csv_size(x = tmp, frac = 0.1, format = FALSE)
#> [1] 91501300