I made this rookie mistake in R
subset(mtcars, cyl = 4)
with single equals =
instead of double equals ==
Why does it fail silently, i.e., return the unfiltered list, instead of breaking with an error?
What's actually happening is that cyl = 4
is being treated as an additional named argument passed on to ...
in subset.data.frame
, and so there actually is no subset
argument to filter with.
As for why it is programmed in such a way as to not throw an error in this case, you'd have to ask R Core for the real answer. But based on how R does it's function argument matching, it seems like it would be a hard thing to detect. Or at least, awkward.
For instance, what if a package implemented a new S3 method for subset
that had an actual additional argument called cyl
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With