It just seems like unnecessary baggage to bring in tidyeval. For example, you could just do this:
quasi_lmer <- function(data, response, group) {
form = paste(response, " ~ (1|", group, ")")
data %>% lme4::lmer(form, data = .)
}
tibble(
batch = rep(1:3, each = 4),
y = rnorm(12, mean = batch)) %>%
quasi_lmer("y", "batch")
Even with an unknown number of fixed and random effects, you can still use strings. For example:
quasi_lmer <- function(data, response, ...) {
ivs = list(...)
form = paste(response, " ~ ", paste(ivs, collapse=" + "))
data %>% lme4::lmer(form, data = .)
}
quasi_lmer(iris, "Sepal.Width", "Sepal.Length", "Petal.Length", "(1|Species)")
As I said earlier, maybe there's some way in which tidyeval increases flexibility or adds other advantages. If there is, I'd be interested in some examples.
If you wanted to use tidyeval, you could do something like the code below, though, once again, I don't know if this is the "right" way to generate model formulas with non-standard evaluation.
quasi_lmer <- function(data, response, ...) {
response = enquo(response)
ivs = enquos(...)
ivs = paste(map(ivs, quo_text), collapse=" + ")
form = paste(quo_text(response), " ~ ", ivs)
data %>% lme4::lmer(form, data = .)
}
quasi_lmer(iris, Sepal.Width, Sepal.Length, Petal.Length, (1|Species))