I'm getting a serious error using ggplot
together with collapse
, in particular, collapse
optimizes computations on factors by giving them an additional class "na.included"
if they are known to not contain any NA
's. This class avoids a missing value check when using factors for grouping, joins etc. see https://sebkrantz.github.io/collapse/reference/qF.html. In the example below, I melt a data frame using collapse::pivot
which adds the "na.included"
class to the generated 'variable' factor i.e. the class is c("factor", "na.included")
. This produces an error in ggplot2
caused by vctrs
. Thanks for considering this issue.
library(collapse) #> collapse 2.0.3, see ?`collapse-package` or ?`collapse-documentation` #> #> Attaching package: 'collapse' #> The following object is masked from 'package:stats': #> #> D library(ggplot2) mtcars |> pivot() |> ggplot(aes(y = value)) + geom_histogram() + facet_wrap( ~ variable) #> Error in `stop_native_implementation()`: #> ! `vec_ptype2.factor.factor()` is implemented at C level. #> This R function is purely indicative and should never be called. #> ℹ This is an internal error that was detected in the vctrs package. #> Please report it at <https://github.com/r-lib/vctrs/issues> with a reprex #> (<https://tidyverse.org/help/>) and the full backtrace. #> Backtrace: #> ▆ #> 1. ├─base::tryCatch(...) #> 2. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers) #> 3. │ ├─base (local) tryCatchOne(...) #> 4. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler) #> 5. │ └─base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh]) #> 6. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 7. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler) #> 8. ├─base::withCallingHandlers(...) #> 9. ├─base::saveRDS(...) #> 10. ├─base::do.call(...) #> 11. ├─base (local) `<fn>`(...) #> 12. └─global `<fn>`(input = base::quote("neat-zebra_reprex.R")) #> 13. └─rmarkdown::render(input, quiet = TRUE, envir = globalenv(), encoding = "UTF-8") #> 14. └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet) #> 15. └─knitr:::process_file(text, output) #> 16. ├─base::withCallingHandlers(...) #> 17. ├─base::withCallingHandlers(...) #> 18. ├─knitr:::process_group(group) #> 19. └─knitr:::process_group.block(group) #> 20. └─knitr:::call_block(x) #> 21. └─knitr:::block_exec(params) #> 22. └─knitr:::eng_r(options) #> 23. ├─knitr:::in_input_dir(...) #> 24. │ └─knitr:::in_dir(input_dir(), expr) #> 25. └─knitr (local) evaluate(...) #> 26. └─evaluate::evaluate(...) #> 27. └─evaluate:::evaluate_call(...) #> 28. ├─evaluate (local) handle(...) #> 29. │ └─base::try(f, silent = TRUE) #> 30. │ └─base::tryCatch(...) #> 31. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers) #> 32. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 33. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler) #> 34. ├─base::withCallingHandlers(...) #> 35. ├─base::withVisible(value_fun(ev$value, ev$visible)) #> 36. └─knitr (local) value_fun(ev$value, ev$visible) #> 37. └─knitr (local) fun(x, options = options) #> 38. ├─base::withVisible(knit_print(x, ...)) #> 39. ├─knitr::knit_print(x, ...) #> 40. └─knitr:::knit_print.default(x, ...) #> 41. └─evaluate (local) normal_print(x) #> 42. ├─base::print(x) #> 43. └─ggplot2:::print.ggplot(x) #> 44. ├─ggplot2::ggplot_build(x) #> 45. └─ggplot2:::ggplot_build.ggplot(x) #> 46. └─layout$setup(data, plot$data, plot$plot_env) #> 47. └─ggplot2 (local) setup(..., self = self) #> 48. └─self$facet$compute_layout(data, self$facet_params) #> 49. └─ggplot2 (local) compute_layout(..., self = self) #> 50. └─ggplot2::combine_vars(data, params$plot_env, vars, drop = params$drop) #> 51. ├─ggplot2:::unique0(vec_rbind0(!!!values[has_all])) #> 52. └─ggplot2:::vec_rbind0(!!!values[has_all]) #> 53. ├─ggplot2:::with_ordered_restart(...) #> 54. │ └─base::withCallingHandlers(...) #> 55. └─vctrs::vec_rbind(..., .error_call = .error_call) #> 56. └─vctrs (local) `<fn>`() #> 57. └─vctrs:::vec_ptype2.factor.factor(...) #> 58. └─vctrs:::stop_native_implementation("vec_ptype2.factor.factor") #> 59. └─cli::cli_abort(...) #> 60. └─rlang::abort(...) # The problem is the additional "na.included" class mtcars |> pivot() |> vclasses() #> variable value #> "factor na.included" "numeric"
Created on 2023-10-26 with reprex v2.0.2
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4