I would like to create a tibble that contains a nested tibble, but also a column outside the nested tibble that refers to a column header within the nested tibble. This is what I mean
library(tidyverse)
tib <- tibble(dat = list(tibble(xvar = 1, freq = 2, rate = 3.2)),
yvar = c(freq)
)
However I get the error "Error in eval_tidy(xs[[j]], mask) : object 'freq' not found"
I want to use the cell contents of tib$yvar as the input into a function that contains a ggplot function eg.
plot_datapoint <- function(dat = tib){
dat_tib <- dat %>% unnest(cols = c(dat))
ggplot(dat_tib, aes(x=xvar, y = yvar)+
geom_point()
I believe the solution has something to do with quosures, but don't know how to implement it.