filter_all_qc: Scoped versions of filter_qc

View source: R/filter_scoped_qc.R

filter_all_qcR Documentation

Scoped versions of filter_qc

Description

filter_all_qc, filter_at_qc, and filter_if_qc return identical objects as filter_all, filter_at, and filter_if respectively, except that they automatically print the number of cases (i.e., rows) that do not meet the filter conditions and that were thus dropped.

Usage

filter_all_qc(.tbl, .vars_predicate, .group_check = F)

filter_at_qc(.tbl, .vars, .vars_predicate, .group_check = F)

filter_if_qc(.tbl, .predicate, .vars_predicate, .group_check = F)

Arguments

.tbl

A tbl object.

.vars_predicate

A quoted predicate expression as returned by all_vars() or any_vars().

Can also be a function or purrr-like formula. In this case, the intersection of the results is taken by default and there's currently no way to request the union.

.group_check

a logical value, that when TRUE, will print a table with each group variable and columns called "n_rows_dropped" and "percent_dropped" that together indicate, for each group, how many row were dropped when performing filter. Default is FALSE, to avoid excess printing. If data is not grouped and .group_check = T, then an error is thrown.

.vars

A list of columns generated by vars(), a character vector of column names, a numeric vector of column positions, or NULL.

.predicate

A predicate function to be applied to the columns or a logical vector. The variables for which .predicate is or returns TRUE are selected. This argument is passed to rlang::as_function() and thus supports quosure-style lambda functions and strings representing function names.

Value

An object of the same class as .data. This object will be identical to that which is returned when running the respective scoped version of dplyr::filter.

See Also

filter_all

Examples

practice_data <- 
  data.frame(
    A = 1:12, 
    B = 6:17, 
    C = 8:19, 
    G = c(rep(c(1, 2), each = 6))
  )


# Scoped filtering
filter_all_qc(practice_data, all_vars(. > 9))
filter_at_qc(practice_data, vars(B, C), any_vars(. > 9))
filter_if_qc(practice_data, is.integer, all_vars(. > 3))

# With grouped data and setting .group_check = T, you can see how many rows
# were dropped per group. Note that this will print a large table if you have 
# a lot of groups.
grouped_data <- group_by(practice_data, G)
filter_all_qc(grouped_data, dplyr::all_vars(. > 9), .group_check = T)


adamMaier/reviewr documentation built on Nov. 5, 2023, 7:21 a.m.