R now also contains a way to quickly create ‘anonymous functions’
# load metafor package
library(metafor)
# copy the BCG vaccine data to 'dat'
dat <- dat.bcg
dat
# compute log risk ratios and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat)
dat
# fit random-effects model to a subset of studies
rma(yi, vi, data=dat, subset=alloc=="random")
# another way of doing the same thing using pipes and an anonymous function
dat |> subset(alloc=="random") |> (function(d) rma(yi, vi, data=d))()
# use the new shorthand syntax to create the anonymous function
dat |> subset(alloc=="random") |> (\(d) rma(yi, vi, data = d))()