r-lib / vctrs

Generic programming with typed R vectors
https://vctrs.r-lib.org
Other
290 stars 66 forks source link

Error in `vec_rbind()` when using ggplot2 for very large dataframe #1923

Closed paluigi closed 7 months ago

paluigi commented 7 months ago

Hello, I am trying to use ggplot2 to create a facet_wrap plot for a dataframe with over 1 billion lines. My code:

ggplot(data = enel_changes) +
  geom_boxplot(aes(x=freq, y=change)) +
  facet_wrap(vars(month), scales="free_y")

The error I get:

Error in `vec_rbind()`:
! Negative `n` in `compact_rep()`.
ℹ In file utils.c at line 897.
ℹ 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 and the full backtrace.
Backtrace:
[90m     ▆
  1. ├─base (local) `<fn>`(x)
  2. ├─ggplot2:::print.ggplot(x)
  3. │ ├─ggplot2::ggplot_build(x)
  4. │ └─ggplot2:::ggplot_build.ggplot(x)
  5. │   └─layout$setup(data, plot$data, plot$plot_env)
  6. │     └─ggplot2 (local) setup(..., self = self)
  7. │       └─self$facet$compute_layout(data, self$facet_params)
  8. │         └─ggplot2 (local) compute_layout(..., self = self)
  9. │           └─ggplot2::combine_vars(data, params$plot_env, vars, drop = params$drop)
 10. │             ├─ggplot2:::unique0(vec_rbind0(!!!values[has_all]))
 11. │             └─ggplot2:::vec_rbind0(!!!values[has_all])
 12. │               ├─ggplot2:::with_ordered_restart(...)
 13. │               │ └─base::withCallingHandlers(...)
 14. │               └─vctrs::vec_rbind(..., .error_call = .error_call)
 15. └─rlang:::stop_internal_c_lib(...)
 16.   └─rlang::abort(message, call = call, .internal = TRUE, .frame = frame)

Possibly related to #1826 , the stack trace seems the same. Please let me know what I can do to help debug.

DavisVaughan commented 7 months ago

It's likely that ggplot2 has ended up attempting to create a data frame with >2 billion rows, hitting R's short vector limit. Unfortunately there isn't much we can do about this in the short term. Supporting long vectors in vctrs is a massive project that we don't plan to work on right now. Closing in favor of https://github.com/r-lib/vctrs/issues/1826 though.