write.fst {fst}R Documentation

Read and write fst files.

Description

Read and write data frames from and to a fast-storage (fst) file. Allows for compression and (file level) random access of stored data, even for compressed datasets. When using a data.table object for x, the key (if any) is preserved, allowing storage of sorted data.

Usage

write.fst(x, path, compress = 0)

read.fst(path, columns = NULL, from = 1, to = NULL,
  as.data.table = FALSE)

Arguments

x

A data frame to write to disk

path

Path to fst file

compress

Value in the range 0 to 100, indicating the amount of compression to use.

columns

Column names to read. The default is to read all all columns.

from

Read data starting from this row number.

to

Read data up until this row number. The default is to read to the last row of the stored dataset.

as.data.table

If TRUE, the result will be returned as a data.table object. Any keys set on dataset x before writing, will be retained. This allows for storage of sorted datasets.

Value

Both functions return a data frame. write.fst invisibly returns x (so you can use this function in a pipeline).

Examples

# Sample dataset
x <- data.frame(A = 1:10000, B = sample(c(TRUE, FALSE, NA), 10000, replace = TRUE))

# Uncompressed
write.fst(x, "dataset.fst")  # filesize: 41 KB
y <- read.fst("dataset.fst") # read uncompressed data

# Compressed
write.fst(x, "dataset.fst", 100)  # fileSize: 4 KB
y <- read.fst("dataset.fst") # read compressed data

# Random access
y <- read.fst("dataset.fst", "B") # read selection of columns
y <- read.fst("dataset.fst", "A", 100, 200) # read selection of columns and rows

[Package fst version 0.7.2 Index]