R/filter.R

Defines functions b_filter b_filter.default b_filter.split_df

Documented in b_filter b_filter.default b_filter.split_df

#' @title Return rows with matching conditions
#' @description Mimics dplyr::filter using base R and rlang
#' @param .data data.frame
#' @param ... Logical predicates defined in terms of the variables in .data
#' @return data.frame
#' @examples
#' airquality%>%
#' b_filter(Temp > 80)%>%
#' head()
#'
#' @seealso
#'  \code{\link[rlang]{quo_squash}},\code{\link[rlang]{quotation}}
#' @rdname b_filter
#' @export
#' @author Jonathan Sidi
b_filter <- function(.data,...){
  UseMethod("b_filter")
}

#' @rdname b_filter
#' @export
#' @importFrom rlang quo_squash quo
b_filter.default <- function(.data,...){
  subset(.data,{
    eval(rlang::quo_squash(rlang::quo(...)))
  })
}

#' @rdname b_filter
#' @export
b_filter.split_df <- function(.data,...){

  bindr(split(.data), b_filter, .data, ...)

}
yonicd/bplyr documentation built on Feb. 24, 2020, 2 p.m.