Open
Description
A fst_table object is expected to mimic the behavior of a data.frame. Therefore, df[0, ]
syntax should return a zero-row table without an error or warning:
tmp_file <- tempfile(".fst")
# write some data
x <- data.frame(X = 1:1000, Y = sample(1:10, 1000, replace = TRUE)) %>%
fst::write_fst(tmp_file)
# get reference to file
fst_table <- fst::fst(tmp_file)
# identical
x[1, ]
#> X Y
#> 1 1 1
fst_table[1, ]
#> X Y
#> 1 1 1
# should be identical
x[0, ]
#> [1] X Y
#> <0 rows> (or 0-length row.names)
fst_table[0, ]
#> Error in read_fst(meta_info$path, from = min_row, to = max_row): Parameter 'from' should have a numerical value equal or larger than 1.
# tibble's also allow zero row syntax
as_tibble(x)[0, ]
#> # A tibble: 0 x 2
#> # ... with 2 variables: X <int>, Y <int>
# as do data.table's
data.table::as.data.table(x)[0. ]
#> Empty data.table (0 rows and 2 cols): X,Y
thanks @hope-data-science for reporting!