[Rd] Additional an example for the forward pipe operator's documentation

Brenton Wiernik brenton @end|ng |rom w|ern|k@org
Sat Jun 19 20:33:37 CEST 2021


> mtcars |> subset(cyl == 4) |> lm(formula = mpg ~ disp)

This isn’t really a reliable approach. It works for `lm()`, where `data` is the second argument, but not for `glm()` unless the first _two_ arguments are named.

mtcars |> subset(cyl == 4) |> glm(formula = mpg ~ disp, family = "gaussian")

It would basically never work for `metafor::rma()`, where `data` is over a dozen arguments into the list. 

In short, reliance on convenient placement of `data` in the argument list probably isn’t something the documentation should encourage.

The anonymous function syntax can be made more aesthetically appealing through effective use of indentation and line breaks (https://twitter.com/bmwiernik/status/1402565800691634182?s=20), eg:

mtcars |> 
  subset(cyl == 4) |>
  ( \(data)
    lm(mpg ~ disp, data = data
  )()



	[[alternative HTML version deleted]]



More information about the R-devel mailing list