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

Reply via email to