Home > database >  map() function error: Error: Can't convert a two-sided formula to a function
map() function error: Error: Can't convert a two-sided formula to a function

Time:11-09

I've got the coefficients related to some linear mixed models and stored into a list in the following way:

models_list_1 <- data_long %>%
  group_by(signals) %>%
  do(fit = lmerTest::lmer(value ~ COND*SES   (1 |ID), data = .)) %>% 
  pull(fit) %>% 
  lapply(., function(x) summary(x)$coefficients) %>% 
  setNames(unique(data_long$signals))

Since I'm interested to reproduce results iteratively into some table, I'm trying running the follwing code

models_list_1 %>%  
  map(.x ~broom::tidy() %>%
    flextable::flextable()
)

But getting back this error

Error: Can't convert a two-sided formula to a function

Does anyone know how to correct syntaxis?

CodePudding user response:

You need to start the formula with ~ and not with .x using map:

models_list_1 %>%  
  map(
    ~ .x %>% broom::tidy() %>% pull(x) %>% as_tibble() %>% flextable::flextable()
  )
  • Related