Slices a data object based on time / date
Examples
conn <- get_connection()
m <- mtcars |>
dplyr::mutate(
"from_ts" = dplyr::if_else(dplyr::row_number() > 10,
as.Date("2020-01-01"),
as.Date("2021-01-01")),
"until_ts" = as.Date(NA))
dplyr::copy_to(conn, m, name = "mtcars", temporary = FALSE)
q <- dplyr::tbl(conn, id("mtcars", conn))
#> Error: `id()` was deprecated in dplyr 0.5.0 and is now defunct.
#> ℹ Please use `vctrs::vec_group_id()` instead.
nrow(slice_time(q, "2020-01-01")) # 10
#> Error in pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE): 1 assertions failed:
#> * Variable '.data': One of the following must apply: *
#> * checkmate::check_class(.data): Must inherit from class 'tbl_dbi', *
#> * but has class 'function' * checkmate::check_data_frame(.data): Must
#> * be of type 'data.frame', * not 'closure' *
#> * checkmate::check_data_table(.data): Must be a data.table, not *
#> * closure * checkmate::check_tibble(.data): Must be a tibble, not
#> * closure.
nrow(slice_time(q, "2021-01-01")) # nrow(mtcars)
#> Error in pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE): 1 assertions failed:
#> * Variable '.data': One of the following must apply: *
#> * checkmate::check_class(.data): Must inherit from class 'tbl_dbi', *
#> * but has class 'function' * checkmate::check_data_frame(.data): Must
#> * be of type 'data.frame', * not 'closure' *
#> * checkmate::check_data_table(.data): Must be a data.table, not *
#> * closure * checkmate::check_tibble(.data): Must be a tibble, not
#> * closure.
close_connection(conn)