I am still trying to improve my understanding how to create a grid table and reference columns either in the grid table or columns in a nested dataset but running into issues with NSE.
I've read the below and tried new things but still couldn't get it to work.
https://dplyr.tidyverse.org/articles/programming.html
Ultimately, I am trying to figure how to use columns from a grid table to identify columns that are nested in a table.
library(tidyverse)
#create tables with columns
sort_tbl <- tibble(sort_col="table")
from_col <- list("x")
delta_col <- list("y","z")
#add columns including arguments column and nest dataset
nested_df <- diamonds %>%
group_by(cut) %>%
nest() %>%
mutate(sort_col="table",
from_col=list("x"),
delta_col=list(delta_col),
arg_col=500
)
#create function that takes input columns from grid table and try to add to dataset
fun <- function(data,from_col,delta_col,sort_col,arg_col) {
data %>%
mutate(across(!!ensym(delta_col),
~!!ensym(from_col)-.x)) %>%
arrange(desc({sort_col})) %>%
mutate(test_col=if_else(price>{arg_col},1,0))
}
#try to add it and but this doesn't work
nested_df %>%
mutate(model=pmap(list(data,
from_col,
delta_col),
~fun(data=data,
from_col=from_col,
delta_col=delta_col,
arg_col=arg_col)
)
)