fst
fst copied to clipboard
Inverse column selection
Is it possible (and if not could it be implemented) to inversely select colums?
If I have a file with columns v1:v5 I could use columns = c("v1", "v2", "v3") I would like to be able to do something like columns = c(-"v4", -"v5") i.e. read all except the specified columns.
Hi @Moohan, thanks for your feature request!
Yes, so something similar to:
# write some sample data with 3 columns
tmp_file <- tempfile(fileext = ".fst")
fst::write_fst(data.frame(X = 1:26, Y = LETTERS, Z = sample(1:100, 26)), tmp_file)
# get reference to file
ft <- fst::fst(tmp_file)
# determine reverse selection of col_sel
col_sel <- c("X", "Z")
rev_sel <- setdiff(colnames(ft), col_sel)
# read all columns but 'X' and 'Z'
fst::read_fst(tmp_file, rev_sel)
#> Y
#> 1 A
#> 2 B
#> 3 C
#> 4 D
#> 5 E
#> ...```
I know that in dplyr that can be done with
select (mydata, -c(mpg, cyl, wt))
The easiest way to implement that behavior in fst would be to allow for an argument reverse_columns that can be set to TRUE to reverse the column selection. Is that a feature that you would regularly use?