An API for reading fst file as data.table.

parse_fst(path)

slice_fst(ft, row_no)

select_fst(ft, ...)

filter_fst(ft, ...)

summary_fst(ft)

Arguments

path

path to fst file

ft

An object of class fst_table, returned by parse_fst

row_no

An integer vector (Positive)

...

The filter conditions

Value

parse_fst returns a fst_table class.

select_fst and filter_fst returns a data.table.

Details

summary_fst could provide some basic information about the fst table.

See also

Examples


  # write the file first
  path = tempfile(fileext = ".fst")
  fst::write_fst(iris,path)
  # parse the file but not reading it
  parse_fst(path) -> ft

  ft
#> <fst file>
#> 150 rows, 5 columns (file333c73e02ce5.fst)
#> 
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
#>         <double>    <double>     <double>    <double>  <factor>
#> 1            5.1         3.5          1.4         0.2    setosa
#> 2            4.9         3.0          1.4         0.2    setosa
#> 3            4.7         3.2          1.3         0.2    setosa
#> 4            4.6         3.1          1.5         0.2    setosa
#> 5            5.0         3.6          1.4         0.2    setosa
#> --            --          --           --          --        --
#> 146          6.7         3.0          5.2         2.3 virginica
#> 147          6.3         2.5          5.0         1.9 virginica
#> 148          6.5         3.0          5.2         2.0 virginica
#> 149          6.2         3.4          5.4         2.3 virginica
#> 150          5.9         3.0          5.1         1.8 virginica

  class(ft)
#> [1] "fst_table"
  lapply(ft,class)
#> $Sepal.Length
#> [1] "numeric"
#> 
#> $Sepal.Width
#> [1] "numeric"
#> 
#> $Petal.Length
#> [1] "numeric"
#> 
#> $Petal.Width
#> [1] "numeric"
#> 
#> $Species
#> [1] "factor"
#> 
  names(ft)
#> [1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"     
  dim(ft)
#> [1] 150   5
  summary_fst(ft)
#> <fst file>
#> 150 rows, 5 columns (file333c73e02ce5.fst)
#> 
#> * 'Sepal.Length': double
#> * 'Sepal.Width' : double
#> * 'Petal.Length': double
#> * 'Petal.Width' : double
#> * 'Species'     : factor

  # get the data by query
  ft %>% slice_fst(1:3)
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>           <num>       <num>        <num>       <num>  <fctr>
#> 1:          5.1         3.5          1.4         0.2  setosa
#> 2:          4.9         3.0          1.4         0.2  setosa
#> 3:          4.7         3.2          1.3         0.2  setosa
  ft %>% slice_fst(c(1,3))
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>           <num>       <num>        <num>       <num>  <fctr>
#> 1:          5.1         3.5          1.4         0.2  setosa
#> 2:          4.7         3.2          1.3         0.2  setosa

  ft %>% select_fst(Sepal.Length)
#>      Sepal.Length
#>             <num>
#>   1:          5.1
#>   2:          4.9
#>   3:          4.7
#>   4:          4.6
#>   5:          5.0
#>  ---             
#> 146:          6.7
#> 147:          6.3
#> 148:          6.5
#> 149:          6.2
#> 150:          5.9
  ft %>% select_fst(Sepal.Length,Sepal.Width)
#>      Sepal.Length Sepal.Width
#>             <num>       <num>
#>   1:          5.1         3.5
#>   2:          4.9         3.0
#>   3:          4.7         3.2
#>   4:          4.6         3.1
#>   5:          5.0         3.6
#>  ---                         
#> 146:          6.7         3.0
#> 147:          6.3         2.5
#> 148:          6.5         3.0
#> 149:          6.2         3.4
#> 150:          5.9         3.0
  ft %>% select_fst("Sepal.Length")
#>      Sepal.Length
#>             <num>
#>   1:          5.1
#>   2:          4.9
#>   3:          4.7
#>   4:          4.6
#>   5:          5.0
#>  ---             
#> 146:          6.7
#> 147:          6.3
#> 148:          6.5
#> 149:          6.2
#> 150:          5.9
  ft %>% select_fst(1:3)
#>      Sepal.Length Sepal.Width Petal.Length
#>             <num>       <num>        <num>
#>   1:          5.1         3.5          1.4
#>   2:          4.9         3.0          1.4
#>   3:          4.7         3.2          1.3
#>   4:          4.6         3.1          1.5
#>   5:          5.0         3.6          1.4
#>  ---                                      
#> 146:          6.7         3.0          5.2
#> 147:          6.3         2.5          5.0
#> 148:          6.5         3.0          5.2
#> 149:          6.2         3.4          5.4
#> 150:          5.9         3.0          5.1
  ft %>% select_fst(1,3)
#>      Sepal.Length Petal.Length
#>             <num>        <num>
#>   1:          5.1          1.4
#>   2:          4.9          1.4
#>   3:          4.7          1.3
#>   4:          4.6          1.5
#>   5:          5.0          1.4
#>  ---                          
#> 146:          6.7          5.2
#> 147:          6.3          5.0
#> 148:          6.5          5.2
#> 149:          6.2          5.4
#> 150:          5.9          5.1
  ft %>% select_fst("Se")
#>      Sepal.Length Sepal.Width
#>             <num>       <num>
#>   1:          5.1         3.5
#>   2:          4.9         3.0
#>   3:          4.7         3.2
#>   4:          4.6         3.1
#>   5:          5.0         3.6
#>  ---                         
#> 146:          6.7         3.0
#> 147:          6.3         2.5
#> 148:          6.5         3.0
#> 149:          6.2         3.4
#> 150:          5.9         3.0

  # return a warning with message
  # \donttest{
    ft %>% select_fst("nothing")
#> Warning: No matched columns,try other patterns. Names of the `fst_table` are listed.
#> [1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"     
  # }

  ft %>% select_fst("Se|Sp")
#>      Sepal.Length Sepal.Width   Species
#>             <num>       <num>    <fctr>
#>   1:          5.1         3.5    setosa
#>   2:          4.9         3.0    setosa
#>   3:          4.7         3.2    setosa
#>   4:          4.6         3.1    setosa
#>   5:          5.0         3.6    setosa
#>  ---                                   
#> 146:          6.7         3.0 virginica
#> 147:          6.3         2.5 virginica
#> 148:          6.5         3.0 virginica
#> 149:          6.2         3.4 virginica
#> 150:          5.9         3.0 virginica
  ft %>% select_fst(cols = names(iris)[2:3])
#>      Sepal.Width Petal.Length
#>            <num>        <num>
#>   1:         3.5          1.4
#>   2:         3.0          1.4
#>   3:         3.2          1.3
#>   4:         3.1          1.5
#>   5:         3.6          1.4
#>  ---                         
#> 146:         3.0          5.2
#> 147:         2.5          5.0
#> 148:         3.0          5.2
#> 149:         3.4          5.4
#> 150:         3.0          5.1

  ft %>% filter_fst(Sepal.Width > 3)
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#>            <num>       <num>        <num>       <num>     <fctr>
#>  1:          5.1         3.5          1.4         0.2     setosa
#>  2:          4.7         3.2          1.3         0.2     setosa
#>  3:          4.6         3.1          1.5         0.2     setosa
#>  4:          5.0         3.6          1.4         0.2     setosa
#>  5:          5.4         3.9          1.7         0.4     setosa
#>  6:          4.6         3.4          1.4         0.3     setosa
#>  7:          5.0         3.4          1.5         0.2     setosa
#>  8:          4.9         3.1          1.5         0.1     setosa
#>  9:          5.4         3.7          1.5         0.2     setosa
#> 10:          4.8         3.4          1.6         0.2     setosa
#> 11:          5.8         4.0          1.2         0.2     setosa
#> 12:          5.7         4.4          1.5         0.4     setosa
#> 13:          5.4         3.9          1.3         0.4     setosa
#> 14:          5.1         3.5          1.4         0.3     setosa
#> 15:          5.7         3.8          1.7         0.3     setosa
#> 16:          5.1         3.8          1.5         0.3     setosa
#> 17:          5.4         3.4          1.7         0.2     setosa
#> 18:          5.1         3.7          1.5         0.4     setosa
#> 19:          4.6         3.6          1.0         0.2     setosa
#> 20:          5.1         3.3          1.7         0.5     setosa
#> 21:          4.8         3.4          1.9         0.2     setosa
#> 22:          5.0         3.4          1.6         0.4     setosa
#> 23:          5.2         3.5          1.5         0.2     setosa
#> 24:          5.2         3.4          1.4         0.2     setosa
#> 25:          4.7         3.2          1.6         0.2     setosa
#> 26:          4.8         3.1          1.6         0.2     setosa
#> 27:          5.4         3.4          1.5         0.4     setosa
#> 28:          5.2         4.1          1.5         0.1     setosa
#> 29:          5.5         4.2          1.4         0.2     setosa
#> 30:          4.9         3.1          1.5         0.2     setosa
#> 31:          5.0         3.2          1.2         0.2     setosa
#> 32:          5.5         3.5          1.3         0.2     setosa
#> 33:          4.9         3.6          1.4         0.1     setosa
#> 34:          5.1         3.4          1.5         0.2     setosa
#> 35:          5.0         3.5          1.3         0.3     setosa
#> 36:          4.4         3.2          1.3         0.2     setosa
#> 37:          5.0         3.5          1.6         0.6     setosa
#> 38:          5.1         3.8          1.9         0.4     setosa
#> 39:          5.1         3.8          1.6         0.2     setosa
#> 40:          4.6         3.2          1.4         0.2     setosa
#> 41:          5.3         3.7          1.5         0.2     setosa
#> 42:          5.0         3.3          1.4         0.2     setosa
#> 43:          7.0         3.2          4.7         1.4 versicolor
#> 44:          6.4         3.2          4.5         1.5 versicolor
#> 45:          6.9         3.1          4.9         1.5 versicolor
#> 46:          6.3         3.3          4.7         1.6 versicolor
#> 47:          6.7         3.1          4.4         1.4 versicolor
#> 48:          5.9         3.2          4.8         1.8 versicolor
#> 49:          6.0         3.4          4.5         1.6 versicolor
#> 50:          6.7         3.1          4.7         1.5 versicolor
#> 51:          6.3         3.3          6.0         2.5  virginica
#> 52:          7.2         3.6          6.1         2.5  virginica
#> 53:          6.5         3.2          5.1         2.0  virginica
#> 54:          6.4         3.2          5.3         2.3  virginica
#> 55:          7.7         3.8          6.7         2.2  virginica
#> 56:          6.9         3.2          5.7         2.3  virginica
#> 57:          6.7         3.3          5.7         2.1  virginica
#> 58:          7.2         3.2          6.0         1.8  virginica
#> 59:          7.9         3.8          6.4         2.0  virginica
#> 60:          6.3         3.4          5.6         2.4  virginica
#> 61:          6.4         3.1          5.5         1.8  virginica
#> 62:          6.9         3.1          5.4         2.1  virginica
#> 63:          6.7         3.1          5.6         2.4  virginica
#> 64:          6.9         3.1          5.1         2.3  virginica
#> 65:          6.8         3.2          5.9         2.3  virginica
#> 66:          6.7         3.3          5.7         2.5  virginica
#> 67:          6.2         3.4          5.4         2.3  virginica
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
  ft %>% filter_fst(Sepal.Length > 6 , Species == "virginica")
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
#>            <num>       <num>        <num>       <num>    <fctr>
#>  1:          6.3         3.3          6.0         2.5 virginica
#>  2:          7.1         3.0          5.9         2.1 virginica
#>  3:          6.3         2.9          5.6         1.8 virginica
#>  4:          6.5         3.0          5.8         2.2 virginica
#>  5:          7.6         3.0          6.6         2.1 virginica
#>  6:          7.3         2.9          6.3         1.8 virginica
#>  7:          6.7         2.5          5.8         1.8 virginica
#>  8:          7.2         3.6          6.1         2.5 virginica
#>  9:          6.5         3.2          5.1         2.0 virginica
#> 10:          6.4         2.7          5.3         1.9 virginica
#> 11:          6.8         3.0          5.5         2.1 virginica
#> 12:          6.4         3.2          5.3         2.3 virginica
#> 13:          6.5         3.0          5.5         1.8 virginica
#> 14:          7.7         3.8          6.7         2.2 virginica
#> 15:          7.7         2.6          6.9         2.3 virginica
#> 16:          6.9         3.2          5.7         2.3 virginica
#> 17:          7.7         2.8          6.7         2.0 virginica
#> 18:          6.3         2.7          4.9         1.8 virginica
#> 19:          6.7         3.3          5.7         2.1 virginica
#> 20:          7.2         3.2          6.0         1.8 virginica
#> 21:          6.2         2.8          4.8         1.8 virginica
#> 22:          6.1         3.0          4.9         1.8 virginica
#> 23:          6.4         2.8          5.6         2.1 virginica
#> 24:          7.2         3.0          5.8         1.6 virginica
#> 25:          7.4         2.8          6.1         1.9 virginica
#> 26:          7.9         3.8          6.4         2.0 virginica
#> 27:          6.4         2.8          5.6         2.2 virginica
#> 28:          6.3         2.8          5.1         1.5 virginica
#> 29:          6.1         2.6          5.6         1.4 virginica
#> 30:          7.7         3.0          6.1         2.3 virginica
#> 31:          6.3         3.4          5.6         2.4 virginica
#> 32:          6.4         3.1          5.5         1.8 virginica
#> 33:          6.9         3.1          5.4         2.1 virginica
#> 34:          6.7         3.1          5.6         2.4 virginica
#> 35:          6.9         3.1          5.1         2.3 virginica
#> 36:          6.8         3.2          5.9         2.3 virginica
#> 37:          6.7         3.3          5.7         2.5 virginica
#> 38:          6.7         3.0          5.2         2.3 virginica
#> 39:          6.3         2.5          5.0         1.9 virginica
#> 40:          6.5         3.0          5.2         2.0 virginica
#> 41:          6.2         3.4          5.4         2.3 virginica
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
  ft %>% filter_fst(Sepal.Length > 6 & Species == "virginica" & Sepal.Width < 3)
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
#>            <num>       <num>        <num>       <num>    <fctr>
#>  1:          6.3         2.9          5.6         1.8 virginica
#>  2:          7.3         2.9          6.3         1.8 virginica
#>  3:          6.7         2.5          5.8         1.8 virginica
#>  4:          6.4         2.7          5.3         1.9 virginica
#>  5:          7.7         2.6          6.9         2.3 virginica
#>  6:          7.7         2.8          6.7         2.0 virginica
#>  7:          6.3         2.7          4.9         1.8 virginica
#>  8:          6.2         2.8          4.8         1.8 virginica
#>  9:          6.4         2.8          5.6         2.1 virginica
#> 10:          7.4         2.8          6.1         1.9 virginica
#> 11:          6.4         2.8          5.6         2.2 virginica
#> 12:          6.3         2.8          5.1         1.5 virginica
#> 13:          6.1         2.6          5.6         1.4 virginica
#> 14:          6.3         2.5          5.0         1.9 virginica