splat: 'Splat' arguments to a function.

View source: R/splat.r

splatR Documentation

‘Splat’ arguments to a function.

Description

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.

Usage

splat(flat)

Arguments

flat

function to splat

Details

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.

Value

a function

Examples

hp_per_cyl <- function(hp, cyl, ...) hp / cyl
splat(hp_per_cyl)(mtcars[1,])
splat(hp_per_cyl)(mtcars)

f <- function(mpg, wt, ...) data.frame(mw = mpg / wt)
ddply(mtcars, .(cyl), splat(f))

plyr documentation built on Oct. 2, 2023, 9:07 a.m.

Related to splat in plyr...