From edd @end|ng |rom deb|@n@org  Tue Jan 12 21:00:43 2021
From: edd @end|ng |rom deb|@n@org (Dirk Eddelbuettel)
Date: Tue, 12 Jan 2021 14:00:43 -0600
Subject: [Rd] [External] brief update on the pipe operator in R-devel
In-Reply-To: <CALEXWq13odcpMsW_e+7e_Vvonx0pCmZHM=t6XNKRubhP4bKxGw@mail.gmail.com>
References: <alpine.DEB.2.21.2012221624270.3391@luke-Latitude-7480>
 <alpine.DEB.2.21.2101121317310.3211@luke-Latitude-7480>
 <CALEXWq13odcpMsW_e+7e_Vvonx0pCmZHM=t6XNKRubhP4bKxGw@mail.gmail.com>
Message-ID: <24573.65515.749231.597977@rob.eddelbuettel.com>


On 12 January 2021 at 20:38, I?aki Ucar wrote:
| On Tue, 12 Jan 2021 at 20:23, <luke-tierney at uiowa.edu> wrote:
| >
| > After some discussions we've settled on a syntax of the form
| >
| >      mtcars |> subset(cyl == 4) |> d => lm(mpg ~ disp, data = d)
| >
| > to handle cases where the pipe lhs needs to be passed to an argument
| > other than the first of the function called on the rhs. This seems a
| > to be a reasonable balance between making these non-standard cases
| > easy to see but still easy to write. This is now committed to R-devel.
| 
| Interesting. Is the use of "d =>" restricted to pipelines? In other
| words, I think that it shouldn't be equivalent to "function(d)", i.e.,
| that this:
| 
| x <- d => lm(mpg ~ disp, data = d)
| 
| shouldn't work.

Looks like your wish was already granted:

  > mtcars |> subset(cyl == 4) |> d => lm(mpg ~ disp, data = d)
  
  Call:
  lm(formula = mpg ~ disp, data = subset(mtcars, cyl == 4))
  
  Coefficients:
  (Intercept)         disp  
       40.872       -0.135  
  
  > d => lm(mpg ~ disp, data = d)
  Error in `=>`(d, lm(mpg ~ disp, data = d)) : could not find function "=>"
  > x <- d => lm(mpg ~ disp, data = d)
  Error in `=>`(d, lm(mpg ~ disp, data = d)) : could not find function "=>"
  > 
  
Dirk

-- 
https://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



[Rd] [External] brief update on the pipe operator in R-devel
Dirk Eddelbuettel