How to perform a `two-step` method dispatch?
Hey there!
I'm trying to set up a "two-step" method dispatch in S7, I'd like my generic function to automatically pick different versions depending on the classes of the arguments, and each version should accept slightly different parameter names.
For example:
```r
method(fun, list(class_character, class_integer, class_numeric)) <- function(x, int_1, num_1) { ... }
method(fun, list(class_numeric, class_integer, class_character)) <- function(x, int_2, chr_1) { ... }
```
Then, when I call it, the right version kicks in based on the order of classes—and I'd use the matching parameter names:
```r
fun(x, int_1 = xxx, num_1 = xxx) # x is character, and uses the first version
fun(x, int_2 = xxx, chr_1 = xxx) # x is numeric, and uses the second version
```
Any idea if this is possible? And if so, what's the cleanest way to pull it off?
Thanks!
0 条评论