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

error when using pmap and srvyr_prop_step_02 #2

Open
avallecam opened this issue Feb 7, 2023 · 0 comments
Open

error when using pmap and srvyr_prop_step_02 #2

avallecam opened this issue Feb 7, 2023 · 0 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@avallecam
Copy link
Owner

library(serosurvey)
library(tidyverse)
library(srvyr)
#> 
#> Attaching package: 'srvyr'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(survey)
#> Loading required package: grid
#> Loading required package: Matrix
#> 
#> Attaching package: 'Matrix'
#> The following objects are masked from 'package:tidyr':
#> 
#>     expand, pack, unpack
#> Loading required package: survival
#> 
#> Attaching package: 'survey'
#> The following object is masked from 'package:graphics':
#> 
#>     dotchart
data(api)
dstrata <- apistrat %>% as_survey_design(strata = stype, weights = pw)
dstrata2 <- apistrat %>%
  mutate(pw2=1) %>%
  as_survey_design(strata = stype, weights = pw2)
dstrata %>%
  summarise(pct = survey_mean(awards=="Yes",proportion = TRUE))
#> # A tibble: 1 × 2
#>     pct pct_se
#>   <dbl>  <dbl>
#> 1 0.639 0.0349
dstrata2 %>%
  summarise(pct = survey_mean(awards=="Yes",proportion = TRUE))
#> # A tibble: 1 × 2
#>     pct pct_se
#>   <dbl>  <dbl>
#> 1 0.565 0.0331

srvyr_prop_step_01(design = dstrata,
                     numerator = awards,
                     denominator = stype) %>%
  mutate(resultado=pmap(.l = select(.,design=design,
                                    numerator = numerator,
                                    denominator = denominator,
                                    numerator_level=numerator_level),
                       .f = srvyr_prop_step_02))
#> Error in `mutate()`:
#> ! Problem while computing `resultado = pmap(...)`.
#> ℹ The error occurred in group 1: stype = E.
#> Caused by error in `pmap()`:
#> ℹ In index: 1.
#> Caused by error in `dplyr::summarise()`:
#> ! Problem while computing `prop = survey_mean(...)`.
#> ℹ The error occurred in group 1: stype = E.
#> Caused by error in `.data$numerator_level`:
#> ! Column `numerator_level` not found in `.data`.

#> Backtrace:
#>      ▆
#>   1. ├─... %>% ...
#>   2. ├─dplyr::mutate(...)
#>   3. ├─dplyr:::mutate.data.frame(...)
#>   4. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), caller_env = caller_env())
#>   5. │   ├─base::withCallingHandlers(...)
#>   6. │   └─mask$eval_all_mutate(quo)
#>   7. ├─purrr::pmap(...)
#>   8. │ └─purrr:::pmap_("list", .l, .f, ..., .progress = .progress)
#>   9. │   ├─purrr:::with_indexed_errors(...)
#>  10. │   │ └─base::withCallingHandlers(...)
#>  11. │   ├─purrr:::call_with_cleanup(...)
#>  12. │   └─serosurvey (local) .f(...)
#>  13. │     └─... %>% ... at serosurvey/R/serosurvey_srvyr.R:154:2
#>  14. ├─dplyr::rename_at(...)
#>  15. │ └─dplyr:::tbl_at_vars(.tbl, .vars, .include_group_vars = TRUE)
#>  16. │   └─dplyr::tbl_vars(tbl)
#>  17. │     ├─dplyr:::new_sel_vars(tbl_vars_dispatch(x), group_vars(x))
#>  18. │     │ └─base::structure(...)
#>  19. │     └─dplyr:::tbl_vars_dispatch(x)
#>  20. ├─dplyr::ungroup(.)
#>  21. ├─dplyr::summarize(...)
#>  22. ├─srvyr:::summarise.grouped_svy(...)
#>  23. │ ├─dplyr::summarise(.data$variables, !!!.dots, .groups = .groups)
#>  24. │ └─dplyr:::summarise.grouped_df(.data$variables, !!!.dots, .groups = .groups)
#>  25. │   └─dplyr:::summarise_cols(.data, dplyr_quosures(...), caller_env = caller_env())
#>  26. │     ├─base::withCallingHandlers(...)
#>  27. │     └─dplyr:::map(quosures, summarise_eval_one, mask = mask)
#>  28. │       └─base::lapply(.x, .f, ...)
#>  29. │         └─dplyr (local) FUN(X[[i]], ...)
#>  30. │           └─mask$eval_all_summarise(quo)
#>  31. ├─srvyr::survey_mean(...)
#>  32. │ └─srvyr:::stop_for_factor(x)
#>  33. │   └─base::is.factor(x)
#>  34. ├─numerator_level
#>  35. ├─rlang:::`$.rlang_data_pronoun`(.data, numerator_level)
#>  36. │ └─rlang:::data_pronoun_get(...)
#>  37. └─rlang:::abort_data_pronoun(x, call = y)
#>  38.   └─rlang::abort(msg, "rlang_error_data_pronoun_not_found", call = call)
ᘀ娂Ȼ
#> Error in eval(expr, envir, enclos): object 'ᘀ娂Ȼ' not found
@avallecam avallecam added the bug Something isn't working label Feb 7, 2023
@avallecam avallecam self-assigned this Feb 7, 2023
@avallecam avallecam added the help wanted Extra attention is needed label Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant