I understand how to use map to iterate over arguments in a df and create a new list column.
For example,
params <- expand.grid(param_a = c(2, 4, 6)
,param_b = c(3, 6, 9)
,param_c = c(50, 100)
,param_d = c(1, 0)
)
df.preprocessed <- dplyr::as.tbl(params) %>%
dplyr::mutate(test_var = purrr::map(param_a, function(x){
rep(5, x)
}
))
However, how do I use the analogous syntax with pmap in the event that I want to specify more than 2 parameters?
df.preprocessed <- dplyr::as.tbl(params) %>%
dplyr::mutate(test_var = purrr::pmap(list(x = param_a
,y = param_b
,z = param_c
,u = param_d), function(x, y){
rep(5,x)*y
}
)
)
Error output:
Error in mutate_impl(.data, dots) : Evaluation error: unused arguments (z = .l[[c(3, i)]], u = .l[[c(4, i)]]).