how to use function for filter tibble

it still works for me.

library(dplyr, warn.conflicts = FALSE)

tb <- tribble(
  ~x , ~y,
  "a", 1,
  "b", 2,
  "c",3,
  "d",4,
  "a", 5,
  "a", 3)

fun <-function(name) {
  z <- tb %>% filter(x == name)
  return(z)
}

fun("a") 
#> # A tibble: 3 x 2
#>   x         y
#>   <chr> <dbl>
#> 1 a         1
#> 2 a         5
#> 3 a         3
tab <- fun("a")
tab
#> # A tibble: 3 x 2
#>   x         y
#>   <chr> <dbl>
#> 1 a         1
#> 2 a         5
#> 3 a         3

Created on 2020-03-29 by the reprex package (v0.3.0.9001)

Please try and build a reprex of your issue so that I can reproduce exactly what you encounter

1 Like