I try to write a simple function wrapping around the purrr::pmap_dbl() function.
I have the following data:
df <- data.frame(
col1 = 1:5,
col2 = 2:6,
col3 = 3:7
)
And the following function:
addfn <- function(x, y){
x^2 + y
}
Then I would like to write a function like:
testfn <- function(data, a, b){
purrr::pmap_dbl(data, function(a, b, ...) addfn(a, b))
}
Unfortunately, testfn(df, col1, col2)
gives an error in this case. I would like to obtain the same output as the output obtained by:
purrr::pmap_dbl(df, function(col1, col2, ...) addfn(col1, col2))
What is the way to do this?