moodymudskipper / inops

Infix Operators for Detection, Subsetting and Replacement
GNU General Public License v3.0
40 stars 0 forks source link

dealing with NAs #39

Open moodymudskipper opened 4 years ago

moodymudskipper commented 4 years ago

@KKPMW Our package functions produce NAs, which might not always be desirable for all situations:

c(1:4) %in{}% c(4,NA,3)
#> [1]   NA   NA TRUE TRUE
c(1:4) %[in{}% c(4,NA,3)
#> [1] NA NA  3  4

do you think it would stay in the scope of the package to add helpers to remove NAs or replace them by FALSE (or by symetry though less useful, by TRUE)

c(1:4) %in{}% na_rm(c(4,NA,3))
#> [1] FALSE FALSE TRUE TRUE

c(1:4) %[in{}% na_rm(c(4,NA,3))
#> [1] 3 4

na_false(c(1:4) %in{}% c(4,NA,3))
#> [1] FALSE FALSE TRUE TRUE
karoliskoncevicius commented 4 years ago

hmm to me it looks a bit too complicated.

If NAs are not desirable we can actually switch that particular behaviour to match %in% instead of ==. But then the inconsistency with [== will still remain.

Another alternative is to provide slightly different operator syntax for dealing with NAs differently. Maybe capital letters %IN{}%, like a "strict" %in{}% But not sure if it's intuitive.

moodymudskipper commented 4 years ago

I think I'd rather not multiply by two our whole set of operators, I miss these functions in a CRAN package, but this might not be the place for them.

karoliskoncevicius commented 4 years ago

Yup, agreed. What is your opinion about the other option - breaking consistency with == just for NA values?

moodymudskipper commented 4 years ago

I'm not sure about it, it's easy to remove NAs or transform them, if they're gone by default you won't get them back.

unrelated FYI : https://github.com/rstudio/rstudio/issues/5767

moodymudskipper commented 4 years ago

I don't completely dislike the capital letter idea though! We can think about it as we use the package.

karoliskoncevicius commented 4 years ago

Yup I agree about not getting NA values back if we get rid of it. Very good point.

About rstudio issue - great catch. I do not use R-studio, so do not have this particular problem. But it would be cumbersome for potential users of the package.