Skip to contents

Search in data frame column if search term is not NULL

Usage

search_in_if(df, dfcol, search)

Arguments

df

A <data.frame> or <tibble>

dfcol

A <character> or <symbol> specifying the column to search in

A <character> or <symbol> specifying the search term

Value

A <data.frame> or <tibble>

Examples

x <- dplyr::tibble(
     y = 1:10,
     z = letters[1:10])

search_in_if(df = x,
             dfcol = x$z,
             search = c("a", "j"))
#> # A tibble: 2 × 2
#>       y z    
#>   <int> <chr>
#> 1     1 a    
#> 2    10 j    

search_in_if(df = x,
             dfcol = x$z,
             search = NULL)
#> # A tibble: 10 × 2
#>        y z    
#>    <int> <chr>
#>  1     1 a    
#>  2     2 b    
#>  3     3 c    
#>  4     4 d    
#>  5     5 e    
#>  6     6 f    
#>  7     7 g    
#>  8     8 h    
#>  9     9 i    
#> 10    10 j