R/f_filter.R

Defines functions f_filter

Documented in f_filter

#' Alternative to `dplyr::filter()`
#'
#' @param data A data frame.
#' @param ... Expressions used to filter the data frame with.
#' @param .by (Optional). A selection of columns to group by for this operation.
#' Columns are specified using tidy-select.
#'
#' @returns
#' A filtered data frame.
#'
#' @export
f_filter <- function(data, ..., .by = NULL){
  group_info <- mutate_summary(data, ..., .by = {{ .by }})
  filter_cols <- group_info[["new_cols"]]
  filter_df <- cheapr::sset_col(group_info[["data"]], filter_cols)
  if (df_ncol(filter_df) < 1){
    data
  } else {
    if (!all(vapply(filter_df, is.logical, FALSE))){
      cli::cli_abort("All expressions in {.fn f_filter} must be logical vectors")
    }
    cheapr::sset_df(data, cpp_which_all(filter_df))
  }
}

Try the fastplyr package in your browser

Any scripts or data that you put into this service are public.

fastplyr documentation built on June 8, 2025, 11:18 a.m.