Skip to contents

Create a filter for a data frame, and add it to a table of filters, where each filter is represented by a row. The filter is only added if the column you specify to filter is valid.

Usage

add_filter(filters, colname, data)

Arguments

filters

A data frame of filters. See filters_init.

colname

A string specifying the column to filter.

data

The data that is to be filtered.

Value

filters with an added row, provided that colname is valid.

Details

The function will either create a character filter or a numeric filter, depending on the type of the column. See filters_init for how these two filters work.

See also

Examples

data <- tibble::tibble(
  x = 1:10,
  y = "a"
)

add_filter(filters_init, "x", data)
#> # A tibble: 1 × 5
#>   type    colname pattern   min   max
#>   <chr>   <chr>   <chr>   <dbl> <dbl>
#> 1 numeric x       NA          1    10
add_filter(filters_init, "y", data)
#> # A tibble: 1 × 5
#>   type      colname pattern   min   max
#>   <chr>     <chr>   <chr>   <dbl> <dbl>
#> 1 character y       ""         NA    NA
add_filter(filters_init, "z", data)
#> # A tibble: 0 × 5
#> # … with 5 variables: type <chr>, colname <chr>, pattern <chr>, min <dbl>,
#> #   max <dbl>