filter function in dplyr errors: object ‘name’ not found

It does seem like you are getting the stats::filter function and not the dplyr one. To make sure you get the right one, use the notation dplyr::filter.

d = data.frame(x=1:10,
 name=c("foo","bar","baz","bar","bar","baz","fnord","qar","qux","quux"))

filter(d, !grepl("ar|ux", name))
Error in grepl("ar|ux", name) : object 'name' not found

dplyr::filter(d, !grepl("ar|ux", name))
  x  name
1 1   foo
2 3   baz
3 6   baz
4 7 fnord

You don’t even need to do library(dplyr) for this to work – you do need dplyr installed though.

This works for functions from any package.

Leave a Comment