Closed njtierney closed 1 year ago
This is all fine - writing as.factor(month)
in there plays havoc with how we parse the bare names of months - if you want to treat it as a factor as is, this is fine.
library(naniar)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
dat_weather <- data.frame(
date = c("2017-01-02","2017-01-03","2017-01-04","2017-01-05","2017-01-06",
"2017-01-07"),
month = c(1,1,1,1,2,2),
temp_min = c(5.9,8.4,10.4,5.8,4.4,NA),
temp_max = c(10.5,11.1,14.5,9.4,9.1, NA),
temp_avg = c(8.4,9.7,12.4,8.1,6.4,NA),
wind_speed_max = c(5.1,5.1,6.7,5.1,5.1, NA)
)
gg_miss_fct(dat_weather, fct = month)
dat_weather %>%
mutate(month = as.factor(month)) %>%
gg_miss_fct(fct = month)
# error persists internally when coercing to factor due to how
# `fct` is parsed
gg_miss_fct(dat_weather, fct = as.factor(month))
#> Error in `tbl_at_vars()`:
#> ! Problem while evaluating `as.factor(month)`.
#> Caused by error in `is.factor()`:
#> ! object 'month' not found
#> Backtrace:
#> ▆
#> 1. ├─naniar::gg_miss_fct(dat_weather, fct = as.factor(month))
#> 2. │ └─... %>% miss_var_summary() at naniar/R/gg-miss-fct.R:29:2
#> 3. ├─naniar::miss_var_summary(.)
#> 4. │ └─naniar:::test_if_null(data) at naniar/R/miss-x-summary.R:47:2
#> 5. ├─dplyr::group_by(., !!fct) at naniar/R/miss-x-summary.R:47:2
#> 6. ├─dplyr::mutate_at(., vars(!!fct), .funs = coerce_fct_na_explicit)
#> 7. │ └─dplyr:::manip_at(...)
#> 8. │ └─dplyr:::tbl_at_syms(...)
#> 9. │ └─dplyr:::tbl_at_vars(tbl, vars, .include_group_vars = .include_group_vars, error_call = error_call)
#> 10. │ └─tidyselect::vars_select(tibble_vars, !!!vars)
#> 11. │ └─tidyselect:::eval_select_impl(...)
#> 12. │ ├─tidyselect:::with_subscript_errors(...)
#> 13. │ │ └─rlang::try_fetch(...)
#> 14. │ │ └─base::withCallingHandlers(...)
#> 15. │ └─tidyselect:::vars_select_eval(...)
#> 16. │ └─tidyselect:::walk_data_tree(expr, data_mask, context_mask)
#> 17. │ └─tidyselect:::eval_c(expr, data_mask, context_mask)
#> 18. │ └─tidyselect:::reduce_sels(node, data_mask, context_mask, init = init)
#> 19. │ └─tidyselect:::walk_data_tree(new, data_mask, context_mask)
#> 20. │ └─tidyselect:::eval_context(expr, context_mask, call = error_call)
#> 21. │ ├─tidyselect:::with_chained_errors(...)
#> 22. │ │ └─rlang::try_fetch(...)
#> 23. │ │ ├─base::tryCatch(...)
#> 24. │ │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 25. │ │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 26. │ │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 27. │ │ └─base::withCallingHandlers(...)
#> 28. │ └─rlang::eval_tidy(as_quosure(expr, env), context_mask)
#> 29. ├─base::as.factor(month)
#> 30. │ └─base::is.factor(x)
#> 31. └─base::.handleSimpleError(...)
#> 32. └─rlang (local) h(simpleError(msg, call))
#> 33. └─handlers[[1L]](cnd)
#> 34. └─rlang::abort(msg, call = call, parent = cnd)
Created on 2023-04-10 with reprex v2.0.2
As described in #250 - just adding an issue here for future reference as I think there might still be another bug in
gg_miss_fct
.Created on 2020-03-03 by the reprex package (v0.3.0)
Should be resolved by #250 - below is the result when building the pkg under #250
Created on 2020-03-03 by the reprex package (v0.3.0)