R/slice_head.R

Defines functions duckplyr_slice_head slice_head.duckplyr_df

# Generated by 02-duckplyr_df-methods.R
#' @export
slice_head.duckplyr_df <- function(.data, ..., n, prop, by = NULL) {
  # Our implementation
  rel_try(NULL,
    "No relational implementation for slice_head()" = TRUE,
    {
      return(out)
    }
  )

  # dplyr forward
  slice_head <- dplyr$slice_head.data.frame
  out <- slice_head(.data, ..., n = n, prop = prop, by = {{ by }})
  return(out)

  # dplyr implementation
  check_dots_empty0(...)

  size <- get_slice_size(n = n, prop = prop)
  idx <- function(n) {
    seq2(1, size(n))
  }

  dplyr_local_error_call()
  dplyr_local_slice_by_arg("by")

  slice(.data, idx(dplyr::n()), .by = {{ by }})
}

duckplyr_slice_head <- function(.data, ...) {
  try_fetch(
    .data <- as_duckplyr_df(.data),
    error = function(e) {
      testthat::skip(conditionMessage(e))
    }
  )
  out <- slice_head(.data, ...)
  class(out) <- setdiff(class(out), "duckplyr_df")
  out
}
duckdblabs/duckplyr documentation built on Nov. 6, 2024, 10 p.m.