moodymudskipper / inops

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

Case for replacement acting as `ifelse()` ? #23

Open karoliskoncevicius opened 4 years ago

karoliskoncevicius commented 4 years ago

While adding examples for replacement operators, I badly wanted to do this:

cars <- rownames(mtcars)
cars %in~% "^Mazda" <- toupper(cars)

Instead of a more elaborate

cars %in~% "^Mazda" <- toupper(cars %[in~% "^Mazda"% )

But on the other hand - this might be a bit confusing. @moodymudskipper what do you think?

moodymudskipper commented 4 years ago

I had the same dilemma when deciding how to code :

cars %in~% "^Mazda" <- toupper
cars %in~% "^Mazda" <- ~ toupper(.)

I think your syntax would be confusing and complexity code that is nicely compact and understandable (easy to investigate from users if edge cases).

Even with my function/formula syntax I think there were caveats that made me decide against it but I m not sure and don't remember which.

We could reintroduce the function notation with your proposed behavior and play with it to see what goes wrong if you want

moodymudskipper commented 4 years ago

If think one case against it was : what if I want to replace missing values by the average?

karoliskoncevicius commented 4 years ago

I see. We probably better leave this for the future.

But one related thing is - what is our strategy with multi-value assignments? Related issue #21

moodymudskipper commented 4 years ago

We might use the formula notation with .x for lhs and .y for subset but now it starts to be confusing again :)