Wraps a function in do.call, so instead of taking multiple arguments, it takes a single named list which will be interpreted as its arguments.
splat(flat)a function
This is useful when you want to pass a function a row of data frame or array, and don't want to manually pull it apart in your function.
hp_per_cyl <- function(hp, cyl, ...) hp / cyl
splat(hp_per_cyl)(mtcars[1,])
#> [1] 18.33333
splat(hp_per_cyl)(mtcars)
#> [1] 18.33333 18.33333 23.25000 18.33333 21.87500 17.50000 30.62500 15.50000
#> [9] 23.75000 20.50000 20.50000 22.50000 22.50000 22.50000 25.62500 26.87500
#> [17] 28.75000 16.50000 13.00000 16.25000 24.25000 18.75000 18.75000 30.62500
#> [25] 21.87500 16.50000 22.75000 28.25000 33.00000 29.16667 41.87500 27.25000
f <- function(mpg, wt, ...) data.frame(mw = mpg / wt)
ddply(mtcars, .(cyl), splat(f))
#> cyl mw
#> 1 4 9.827586
#> 2 4 7.648903
#> 3 4 7.238095
#> 4 4 14.727273
#> 5 4 18.823529
#> 6 4 18.474114
#> 7 4 8.722110
#> 8 4 14.108527
#> 9 4 12.149533
#> 10 4 20.092531
#> 11 4 7.697842
#> 12 6 8.015267
#> 13 6 7.304348
#> 14 6 6.656299
#> 15 6 5.231214
#> 16 6 5.581395
#> 17 6 5.174419
#> 18 6 7.111913
#> 19 8 5.436047
#> 20 8 4.005602
#> 21 8 4.029484
#> 22 8 4.638070
#> 23 8 4.021164
#> 24 8 1.980952
#> 25 8 1.917404
#> 26 8 2.750234
#> 27 8 4.403409
#> 28 8 4.425036
#> 29 8 3.463542
#> 30 8 4.993498
#> 31 8 4.984227
#> 32 8 4.201681