Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How can I use NSE and filter an expression using ... (ellipsis)?

$
0
0

How can I utilize the magic dots (...) / ellipsis in order to filter based off an arbitrary column?

df = tibble::tibble(col1 = c('a', 'b', 'c'), col2 = c(1,3,4))

my_func = function(x, ...){
  df %>%
    dplyr::filter(... == x)
}

my_func('a', col1)


# Should return:
# A tibble: 1 x 2
  col1   col2
  <chr> <dbl>
1 a         1

Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>