When {dplyr} or {tidyr} verbs are applied to a data.table or a database connection, they do not output data frames but objects like dtplyr_step or tbl_sql that are called lazy data frames. The actual process is triggered by using as_dtx()
, or more explicitly with dplyr::collect()
which coerces the result to a tibble. If you want the default {svBase} data frame object instead, use collect_dtx()
, or if you want a specific object, use one of the other variants.
Arguments
- x
A data.frame, data.table, tibble or a lazy data frame (dtplyr_step, tbl_sql...).
- ...
Arguments passed on to methods for
dplyr::collect()
.
Value
A data frame (data.frame, data.table or tibble's tbl_df), the default version for collect_dtx()
.
Examples
# Assuming the default data frame for svBase is a data.table
mtcars_dtt <- as_dtt(mtcars)
library(dplyr)
library(dtplyr)
# A lazy data frame, not a "real" data frame!
mtcars_dtt |> lazy_dt() |> select(mpg:disp) |> class()
#> [1] "dtplyr_step_subset" "dtplyr_step"
# A data frame
mtcars |> select(mpg:disp) |> class()
#> [1] "data.frame"
# A data table
mtcars_dtt |> select(mpg:disp) |> class()
#> [1] "data.table" "data.frame"
# A tibble, always!
mtcars_dtt |> lazy_dt() |> select(mpg:disp) |> collect() |> class()
#> [1] "tbl_df" "tbl" "data.frame"
# The data frame object you want, default one specified for svBase
mtcars_dtt |> lazy_dt() |> select(mpg:disp) |> collect_dtx() |> class()
#> [1] "data.table" "data.frame"