I am not saying this is wonderful but this does work: penguins |> subset(species != "Gentoo") |> stats:::t.test.formula(formula = bill_len ~ species)
Also there is a problem with t.test in that methods are not supposed to have conflicting signatures but > args(t.test) function (x, ...) NULL > args(stats:::t.test.formula) function (formula, data, subset, na.action = na.pass, ...) NULL On Tue, Jun 10, 2025 at 6:39 AM Måns Thulin <gausseliminer...@gmail.com> wrote: > > To use functions for common statistical tests/models, like t.test, > wilcox.test, lm, glm, and aov, we must currently use the pipe placeholder _ > when using pipes: > > penguins |> > subset(species != "Gentoo") |> > t.test(bill_len ~ species, data = _) > > The syntax would be cleaner and perhaps more intuitive if we didn't have to > add the `data = _` bit: > > penguins |> > subset(species != "Gentoo") |> > t.test(bill_len ~ species) > > I believe that this is how t.test and the other functions I mentioned would > have worked if they'd been written after the base pipe was introduced. > > Currently, t.test and friends only accept a vector and/or a formula as > their first argument. Since there already is a formula method for these > functions, a simple way to make the second example above work would be to > define a data.frame method like so: > > t.test.data.frame <- function(x, formula, ...) > { > t.test.formula(formula, x, ...) > } > > ...perhaps with a check to make sure that the formula argument actually is > a formula. > > Now, this seems like an easy thing to fix, and it doesn't break any > existing functionality of these functions. Since the base pipe was > introduced four years ago, I suspect that there might be some reason why > this hasn't been implemented already, and I'm curious to find out what that > is. Or, if there is support for the idea above, I'd be happy to submit a > feature request in Bugzilla and provide code for implementing this. > > Best regards, > Måns > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel