Consider this simple example
testdf <- data_frame(col1 = c(2, 2),
col2 = c(1, 2))
# A tibble: 2 x 2
col1 col2
<dbl> <dbl>
1 2 1
2 2 2
Then I have another tibble, which contains the arguments I want to feed to map2
mapdf <- data_frame(myinput = c('col1', 'col2'),
myoutput = c('col2', 'col1'))
# A tibble: 2 x 2
myinput myoutput
<chr> <chr>
1 col1 col2
2 col2 col1
And here is the simple function
myfunc <- function(input, output){
output <- sym(output)
input <- sym(input)
testdf %>% mutate(!!input := !!output + 1)
}
For instance, at the first iteration this is simply equal to:
> testdf %>% mutate(col1 = col2 + 1)
# A tibble: 2 x 2
col1 col2
<dbl> <dbl>
1 2 1
2 3 2
However, my purrr
attempt below returns an empty dataframe. What is the issue here?
> mapdf %>% map2_dfr(.$myinput, .$myoutput, myfunc(.x, .y))
# A tibble: 0 x 0
Thanks!