Skip to contents

Call a Function with Argument Combinations from a Data Frame

Usage

callWithData(
  FUN,
  data,
  ...,
  threshold = 0.5,
  SIMPLIFY = TRUE,
  USE.NAMES = TRUE
)

Arguments

FUN

function to be called

data

data frame with one column per argument of FUN

...

further (constant) arguments to FUN that are passed to mapply via MoreArgs

threshold

if the ratio of unique value combinations in the relevant columns in data to all value combinations in these columns is below this threshold value then FUN will be called only with the unique value combinations. This should increase performance.

SIMPLIFY

passed tomapply, default: TRUE

USE.NAMES

passed tomapply, default: TRUE

Value

vector of length nrow(data) with the result values returned by

FUN

Examples

combis <- expand.grid(x = 1:2, y = c(10, 20, 30))
combis
#>   x  y
#> 1 1 10
#> 2 2 10
#> 3 1 20
#> 4 2 20
#> 5 1 30
#> 6 2 30

callWithData(`+`, combis)
#> -> Calling +() for all 6 value combinations ... ok. (0.00 secs) 
#> [1] 11 12 21 22 31 32