Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: rlang::sym() doesn't work for lm_lin #413

Open
bfifield opened this issue Oct 16, 2024 · 2 comments
Open

Bug: rlang::sym() doesn't work for lm_lin #413

bfifield opened this issue Oct 16, 2024 · 2 comments
Labels

Comments

@bfifield
Copy link

bfifield commented Oct 16, 2024

I'm attempting to map() over a series of outcomes and apply lm_lin() to each outcome separately with a uniform set of control variables. However, when I do, I get the error:

Error in `map()`:
ℹ In index: 1.
Caused by error in `sym()`:
! could not find function "sym"
Run `rlang::last_trace()` to see where the error occurred.

This does not happen when using lm_robust(), which runs fine. I've included a reproducible example below:

library(tidyverse)
library(estimatr)

N = 100
df <- data.frame(
  outcome_a = rbinom(N, 1, .5),
  outcome_b = rbinom(N, 1, .5),
  treatment = rbinom(N, 1, .5),
  cov = rbinom(N, 1, .5)
)

outcomes <- c("outcome_a", "outcome_b")

# Works
outcomes |>
  map(
    ~lm_robust(!!sym(.x) ~ treatment + cov, data = df) |> 
      tidy() |>
      mutate(outcome = .x)
  ) |> bind_rows()

# Does not work
outcomes |>
  map(
    ~lm_lin(!!sym(.x) ~ treatment, covariates = ~ cov, data = df) |> 
      tidy() |>
      mutate(outcome = .x)
  ) |> bind_rows()
@macartan
Copy link

macartan commented Oct 16, 2024 via email

@bfifield
Copy link
Author

Thanks, @macartan - confirming this runs correctly for me. Keeping the issue open given that behavior is not consistent between lm_robust and lm_lin.

@graemeblair graemeblair added the bug label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants