bstfun icon indicating copy to clipboard operation
bstfun copied to clipboard

Error with add_continuous_stat function

Open TomVillenet opened this issue 5 months ago • 0 comments

I've been experiencing difficulties for the past 2 days using the "add_continous_stat" function (which was working perfectly 6 months ago with the same code)

Here's the code from documentation for easier reproductability

library(dplyr) set.seed(1123) likert_lvls <- c("Never", "Sometimes", "Often", "Always")

df <- tibble::tibble( Q1 = sample(likert_lvls, size = 100, replace = TRUE), Q2 = sample(likert_lvls, size = 100, replace = TRUE) ) %>% mutate(across(c(Q1, Q2), ~factor(., levels = likert_lvls)))

tbl_likert_ex1 <- tbl_likert(df) %>% add_n() %>% add_continuous_stat(statistic = "{mean}") %>% add_continuous_stat(statistic = "{sd}")

And here's the error message :

Error in purrr::map():

ℹ In index: 1. Caused by error in scope_tidy(): ! The .$x data frame does not have the required "variable" column.


Backtrace: ▆

  1. ├─... %>% add_continuous_stat(statistic = "{sd}")
  2. ├─bstfun::add_continuous_stat(., statistic = "{sd}")
  3. ├─bstfun::add_continuous_stat(., statistic = "{mean}")
  4. ├─gtsummary::add_n(.)
  5. ├─bstfun::tbl_likert(df)
  6. │ └─... %>% structure(class = c("tbl_likert", "gtsummary"))
  7. ├─base::structure(., class = c("tbl_likert", "gtsummary"))
  8. ├─purrr::list_modify(., inputs = func_inputs)
  9. │ └─purrr:::check_list(.x)
  10. ├─gtsummary::tbl_butcher(.)
  11. ├─gtsummary::tbl_stack(., quiet = TRUE)
  12. ├─purrr::map(...)
  13. │ └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
  14. │ ├─purrr:::with_indexed_errors(...)
  15. │ │ └─base::withCallingHandlers(...)
  16. │ ├─purrr:::call_with_cleanup(...)
  17. │ └─bstfun (local) .f(.x[[i]], ...)
  18. │ ├─... %>% ...
  19. │ └─gtsummary::tbl_summary(...)
  20. │ └─... %>% ...
  21. ├─gtsummary::modify_table_body(...)
  22. │ └─gtsummary:::.assert_class(x, "gtsummary")
  23. ├─gtsummary::modify_header(., gtsummary::all_stat_cols() ~ "{level}")
  24. └─gtsummary::modify_header(...)
  25. └─gtsummary:::.combine_update_and_dots(x, update, ...)
  26. └─broom.helpers::.formula_list_to_named_list(...)
    
  27.   └─broom.helpers:::.single_formula_to_list(...)
    
  28.     └─broom.helpers::.select_to_varnames(...)
    
  29.       └─broom.helpers::scope_tidy(var_info, data)
    

TomVillenet avatar Sep 25 '24 15:09 TomVillenet