Obtain one chunk by chunk id

get_chunk(...)

# S3 method for disk.frame
get_chunk(df, n, keep = NULL, full.names = FALSE, ..., partitioned_info = NULL)

Arguments

...

passed to fst::read_fst or whichever read function is used in the backend

df

a disk.frame

n

the chunk id. If numeric then matches by number, if character then returns the chunk with the same name as n

keep

the columns to keep

full.names

whether n is the full path to the chunks or just a relative path file name. Ignored if n is numeric

partitioned_info

for internal use only. It's a data.frame used to help with filtering by partitions

Examples

cars.df = as.disk.frame(cars, nchunks = 2)
get_chunk(cars.df, 1)
#>     speed dist
#>  1:     4    2
#>  2:     4   10
#>  3:     7    4
#>  4:     7   22
#>  5:     8   16
#>  6:     9   10
#>  7:    10   18
#>  8:    10   26
#>  9:    10   34
#> 10:    11   17
#> 11:    11   28
#> 12:    12   14
#> 13:    12   20
#> 14:    12   24
#> 15:    12   28
#> 16:    13   26
#> 17:    13   34
#> 18:    13   34
#> 19:    13   46
#> 20:    14   26
#> 21:    14   36
#> 22:    14   60
#> 23:    14   80
#> 24:    15   20
#> 25:    15   26
#>     speed dist
get_chunk(cars.df, 2)
#>     speed dist
#>  1:    15   54
#>  2:    16   32
#>  3:    16   40
#>  4:    17   32
#>  5:    17   40
#>  6:    17   50
#>  7:    18   42
#>  8:    18   56
#>  9:    18   76
#> 10:    18   84
#> 11:    19   36
#> 12:    19   46
#> 13:    19   68
#> 14:    20   32
#> 15:    20   48
#> 16:    20   52
#> 17:    20   56
#> 18:    20   64
#> 19:    22   66
#> 20:    23   54
#> 21:    24   70
#> 22:    24   92
#> 23:    24   93
#> 24:    24  120
#> 25:    25   85
#>     speed dist
get_chunk(cars.df, 1, keep = "speed")
#>     speed
#>  1:     4
#>  2:     4
#>  3:     7
#>  4:     7
#>  5:     8
#>  6:     9
#>  7:    10
#>  8:    10
#>  9:    10
#> 10:    11
#> 11:    11
#> 12:    12
#> 13:    12
#> 14:    12
#> 15:    12
#> 16:    13
#> 17:    13
#> 18:    13
#> 19:    13
#> 20:    14
#> 21:    14
#> 22:    14
#> 23:    14
#> 24:    15
#> 25:    15
#>     speed

# if full.names = TRUE then the full path to the chunk need to be provided
get_chunk(cars.df, file.path(attr(cars.df, "path"), "1.fst"), full.names = TRUE)
#>     speed dist
#>  1:     4    2
#>  2:     4   10
#>  3:     7    4
#>  4:     7   22
#>  5:     8   16
#>  6:     9   10
#>  7:    10   18
#>  8:    10   26
#>  9:    10   34
#> 10:    11   17
#> 11:    11   28
#> 12:    12   14
#> 13:    12   20
#> 14:    12   24
#> 15:    12   28
#> 16:    13   26
#> 17:    13   34
#> 18:    13   34
#> 19:    13   46
#> 20:    14   26
#> 21:    14   36
#> 22:    14   60
#> 23:    14   80
#> 24:    15   20
#> 25:    15   26
#>     speed dist

# clean up cars.df
delete(cars.df)