Copies data from GPU memory back to R as a tibble. This is typically the final step in a GPU data manipulation pipeline, after filtering, mutating, and selecting the data you need.
Usage
# S3 method for class 'tbl_gpu'
collect(x, ...)Arguments
- x
A
tbl_gpuobject created bytbl_gpu().- ...
Additional arguments (ignored, included for compatibility).
Value
A tibble::tibble containing the data from the GPU table (a
grouped_df, with the same .drop, when x is grouped, as for
dplyr::collect() on a database table). A table uploaded from a plain
data.frame comes back as a bare data.frame while it is ungrouped, and
custom data-frame attributes (attr(df, "foo")) are kept the way dplyr
keeps them through verbs.
Column types are converted back to R types:
FLOAT64/FLOAT32 -> numeric (double)
INT8/INT16/INT32, UINT8/UINT16 -> integer
UINT32 -> double (exact)
INT64/UINT64 ->
bit64::integer64(a double with a warning whenbit64is absent and a value is past 2^53); a UINT64 value pastINT64_MAXis an error, never a wrapSTRING -> character
BOOL8 -> logical (TRUE/FALSE)
DATE (TIMESTAMP_DAYS) ->
Date; TIMESTAMP_SECONDS/MILLISECONDS/ MICROSECONDS/NANOSECONDS ->POSIXct(nanoseconds finer than a microsecond are rounded, with a warning)DURATION_DAYS ->
difftimein days; the other DURATION_* ->difftimein seconds (a warning past 2^53 ticks)DECIMAL32/64/128 -> double, the nearest one (a warning when it needs more than 15 significant digits; an error beyond the double range)
a dictionary with string keys -> factor
Any other type (LIST, STRUCT, a dictionary with other keys) is an error of
class cuplyr_error_unsupported_gpu_type naming the column; the warnings
have class cuplyr_warning_collect_precision and name every column
concerned. print() and glimpse() show such a column as a placeholder.
Details
Grouped tables and .drop
The .drop setting of group_by() travels with the table through the
verbs that keep at least one group column (and is reset to the default when
none is left; group_by() on a grouped table keeps it unless given a new
.drop), so group_by(f, .drop = FALSE) |> arrange(x) |> collect() still
keeps empty factor-level groups. Empty groups of a non-factor column
that filter() or slice() emptied are not kept, unlike in dplyr, except after
slice(.preserve = TRUE), which keeps its input's group keys: see the .drop
section of group_by().
See also
tbl_gpu for creating GPU tables,
filter.tbl_gpu, select.tbl_gpu for reducing data
Examples
library(dplyr)
if (has_gpu()) {
gpu_mtcars <- tbl_gpu(mtcars)
# Process on GPU, then collect
result <- gpu_mtcars |>
filter(mpg > 20) |>
mutate(kpl = mpg * 0.425) |>
select(mpg, kpl, hp) |>
collect()
# Result is a regular tibble
class(result)
print(result)
}
#> mpg kpl hp
#> 1 21.0 8.9250 110
#> 2 21.0 8.9250 110
#> 3 22.8 9.6900 93
#> 4 21.4 9.0950 110
#> 5 24.4 10.3700 62
#> 6 22.8 9.6900 95
#> 7 32.4 13.7700 66
#> 8 30.4 12.9200 52
#> 9 33.9 14.4075 65
#> 10 21.5 9.1375 97
#> 11 27.3 11.6025 66
#> 12 26.0 11.0500 91
#> 13 30.4 12.9200 113
#> 14 21.4 9.0950 109
