R/helpful_dplyr.R

Defines functions filter_loudly

Documented in filter_loudly

#' Filter loudly
#' @description Filter with message of how many rows have been filtered
#' @param ... Pass through to \code{dplyr::filter()}
#' @return Filtered data with message of how many rows have been filtered
#' @examples
#' mtcars %>% filter_loudly(mpg == 6)
#' @export

filter_loudly <- function(.data, ...){
  in_rows <- nrow(.data)
  out <- filter(.data, ...)
  out_rows <- nrow(out)
  message("Filtered out ", in_rows - out_rows, " rows.")
  out
}

#' Not In: Inverse Value Matching
#' @description Returns a logical vector indicating if there is NOT a match for the LHS vector anywhere in the RHS vector. Opposide of \code{\%in\%}.
#' @usage x %ni% y
#' @param x vector or NULL: the values to check for non-match
#' @param y vector or NULL: the values to be matched against
#' @return A logical vector, indicating if there was no match for each element of x. Values are TRUE or FALSE and never NA
#' @rdname ni
#' @export
"%ni%" <- Negate("%in%")
tojyouso/tojyouso documentation built on May 29, 2019, 9:32 a.m.