Benjamin Fretwurst
Benjamin Fretwurst

Reputation: 189

Why not single = in dplyr::filter

Sorry for that question against a convention. The single = in filter() is the most common error made by me and my students. One of my students asked me, what the single equal sign is needed for in filter() other than comparing. We both understand, that in other contexts the = is used to define a variable or an object. Her argument is, that in filter(), the error handler always say probably you forgot to write two == So why could filter() not accept both? The absolute correct == and in context of filter() unambiguous =?

I‘m asking for the argument. So this question is meant as a question and not a suggestion! :-)

Upvotes: 0

Views: 77

Answers (1)

mpianko
mpianko

Reputation: 38

My thought is that dplyr::filter is requiring using “==“ to test a logical statement in order to properly filter, and that the code doesn’t work with an assignment operator (“=“ or “<-“ which are equivalent in R). Having multiple definitions for “=“ would cause too much confusion in R in my opinion.

Upvotes: 1

Related Questions