Re: [Rd] Augment base::replace(x, list, value) to allow list= to be a predicate?

2023-03-08 Thread Gabor Grothendieck
This is getting way off topic. I wasn't suggesting that gsubfn, which does a lot more than this simple example, as the implementation. I was pointing out that the replace function idea can be extended to sub and gsub and showing what it would do. On Tue, Mar 7, 2023 at 9:41 PM Steve Martin

Re: [Rd] Augment base::replace(x, list, value) to allow list= to be a predicate?

2023-03-07 Thread Steve Martin
That's an interesting example, as it's conceptually similar to what Pavel is proposing, but structurally different. gsubfn() is more complicated than a simple switch in the body of the function, and wouldn't work well as an anonymous function. Multiple dispatch can nicely encompass both of these

Re: [Rd] Augment base::replace(x, list, value) to allow list= to be a predicate?

2023-03-07 Thread Gabor Grothendieck
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 wrote: > > Dear All, > > Currently, list= in base::replace(x, list,

Re: [Rd] Augment base::replace(x, list, value) to allow list= to be a predicate?

2023-03-07 Thread Pavel Krivitsky
Dear Serguei, On Mon, 2023-03-06 at 09:45 +0100, Serguei Sokol wrote: > Right, but anonymous function syntax can palliate to this: > > x |> (\(x) replace(x, is.na(x), 0))() This approach hardly makes for concise or readable code. > > Before modifying the base of R, we should examine existing

Re: [Rd] Augment base::replace(x, list, value) to allow list= to be a predicate?

2023-03-06 Thread Serguei Sokol via R-devel
Le 04/03/2023 à 01:21, Pavel Krivitsky a écrit : Dear All, Currently, list= in base::replace(x, list, value) has to be an index vector. For me, at least, the most common use case is for list= to be some simple property of elements of x, e.g., x <- c(1,2,NA,3) replace(x, is.na(x), 0)