I think the point is not that there needs to be a smaller package for yet
another if-else (https://xkcd.com/927/). It is that if the R-language, as a
whole, had a performant if-else in the base of the language would benefit
**everyone** such that a data.table or dplyr or gtools etc. alternative
would not be necessary.

On Tue, Jul 8, 2025 at 5:09 AM Ben Bolker <bbol...@gmail.com> wrote:

>    I think Duncan's point is that R-core are (reasonably) very, very,
> very conservative about adding things to base R. It would be useful to
> the community, and would indeed further the discussion, to make a tiny
> package containing just that function. (Even just copying it from some
> other package might require some work to disentangle it from
> dependencies: for example, a quick glance at dplyr::if_else shows that
> it uses functions from rlang, vctrs, ...)
>
>    I'd be happy to accept a pull request in `gtools`, which is a
> zero-dependency (except base R) package for small utility functions ...
>
>    cheers
>     Ben Bolker
>
>
> On 7/8/25 07:36, Antoine Fabri wrote:
> > It's not about asking others to do it really, that was a harsh
> assumption.
> > I'd be happy to propose a version if it helps, I'd be also very happy if
> it
> > were just a copy of if_else or fifelse (both MIT FWIW).
> > It's a low level building block and it's broken, IMO it's way better to
> > have it available and documented in base R and incite everyone to use it,
> > so not only we don't suffer from it in the code we write, but also in the
> > code we use or inherit from.
> >
> > Le mar. 8 juil. 2025 à 13:25, Duncan Murdoch <murdoch.dun...@gmail.com>
> a
> > écrit :
> >
> >> Rather than asking others to do this, why don't you create a tiny
> >> package containing nothing other than an ifelse() replacement?  I
> >> wouldn't want to depend on dplyr or data.table just to get their
> >> versions, but depending on your tiny package wouldn't be an issue.
> >>
> >> Duncan Murdoch
> >>
> >> On 2025-07-08 6:12 a.m., Antoine Fabri wrote:
> >>> Dear r-devel,
> >>>
> >>> `ifelse()` has a lot of issues, and for these reasons it has been
> redone
> >> in
> >>> `dplyr::if_else()` and `data.table::fifelse()`, which are both great.
> Yet
> >>> it's an important base R function, it's really hard to program in base
> R
> >>> without it and scores probably as high as it gets in the most_used *
> >>> most_problematic metric.
> >>>
> >>> Obviously we can't change it without breaking a ton of code, but with
> all
> >>> the experience we now have with it and the dplyr and data.table
> >> alternative
> >>> maybe it might not be absurd to have a good alternative, say `if.else`
> in
> >>> base R, that we can document on the same page and recommend for future
> >> use.
> >>> It would require a common type in yes/no, not return logical() for all
> >> zero
> >>> length input, work with dates, datetimes and factors, handle a na
> >> condition
> >>> etc. The test suites of dplyr and data.table probably tell us
> everything
> >>> about the edge cases we want to look at. Maybe the old ifelse could
> even
> >>> warn when called from the top level, to incite us to work with the new
> >> one.
> >>>
> >>> It feels wrong to me to be stuck with ifelse() forever just because it
> >> has
> >>> been like this for a long time. I'm sure some of you learnt your way
> >> around
> >>> it but I work with R every day and after 10+ years of R it still bites
> me
> >>> all the time, I'm probably not alone, at least chatGPT called it a
> >>> "footgun", and we don't want that :).
> >>>
> >>> Thanks,
> >>>
> >>> Antoine
> >>>
> >>>        [[alternative HTML version deleted]]
> >>>
> >>> ______________________________________________
> >>> R-devel@r-project.org mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-devel
> >>
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> --
> Dr. Benjamin Bolker
> Professor, Mathematics & Statistics and Biology, McMaster University
> Director, School of Computational Science and Engineering
> * E-mail is sent at my convenience; I don't expect replies outside of
> working hours.
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to