search for: s7_dispatch

Displaying 2 results from an estimated 2 matches for "s7_dispatch".

Did you mean: _dispatch
2023 Mar 08
1
Augment base::replace(x, list, value) to allow list= to be a predicate?
...le switch in the body of the function, and wouldn't work well as an anonymous function. Multiple dispatch can nicely encompass both of these cases. For replace(), library(S7) replace <- new_generic("replace", c("x", "list"), function(x, list, values, ...) { S7_dispatch() }) method(replace, list(class_any, class_any)) <- base::replace method(replace, list(class_any, class_function)) <- function(x, list, values, ...) { replace(x, list(x, ...), values) } x <- c(1 ,2, NA, 3) replace(x, is.na(x), 0) [1] 1 2 0 3 replace(x, is.na, 0) [1] 1 2 0 3 And for...
2023 Mar 07
1
Augment base::replace(x, list, value) to allow list= to be a predicate?
This could be extended to sub and gsub as well which gsubfn in the gusbfn package already does: library(gsubfn) gsubfn("^..", toupper, c("abc", "xyz")) ## [1] "ABc" "XYz" On Fri, Mar 3, 2023 at 7:22?PM Pavel Krivitsky <p.krivitsky at unsw.edu.au> wrote: > > Dear All, > > Currently, list= in base::replace(x, list, value)