So, I'm asking this as a follow-up to another question, to the solution to which I thought would fix all of my problems. It seems like that's not the case. Take the following setup
library(tidyverse)
set.seed(1)
mytib <- tibble(a = as.character(c(1:5, NA)),
b = as.character(c(6:8, NA, 9:10)),
c = as.character(sample(x = c(0,1), size = 6, replace = TRUE)))
vars <- c("a", "b")
Taking the function Ritchie Sacramento created in the other post
convert_tib <- function(tib, var) {
tib %>%
transmute(across(c(var, c), as.integer)) %>%
filter(!is.na(.data[[var]]))
}
I would like to add another function call within that function. The idea is that I first transform and filter my variables (code above) and then I feed it into this function experiment::ATEnocov(Y = a, Z = c, data = tib)
to obtain the average treatment effect for the transformed and filtered data. I'd then like to run the whole function with purrr:map
across a bunch of variables.
Unfortunately, adding this function call at the end of the convert_tib
function produces the error message Error in eval(call$Y, envir = data) : object 'a' not found
. Quite clearly this has to do with the environments in which ATEnocov
is called but I just can't figure out how to feed the variable into the function inside the same function.