Skip to content

“Computation failed in stat_count() when using loadRDS #3745

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

Closed
nick-youngblut opened this issue Jan 20, 2020 · 6 comments
Closed

“Computation failed in stat_count() when using loadRDS #3745

nick-youngblut opened this issue Jan 20, 2020 · 6 comments
Labels
reprex needs a minimal reproducible example

Comments

@nick-youngblut
Copy link

I often save my ggplot objects with saveRDS() so that I can load & plot them latter in new sessions. This works quite well, except when I use geom_bar(), which creates the following warning:

Warning message:
“Computation failed in `stat_count()`:
Please use `data_frame()` or `new_data_frame()` instead of `data.frame()` for better performance. See the vignette "ggplot2 internal programming guidelines" for details.”

...and results in an empty plot.

Reprex:

Session 1:

library(dplyr)
library(ggplot2)
out_file = 'ggplot_obj.RDS'
mpg %>%
    ggplot(aes(class)) +
    geom_bar() %>%
    saveRDS(file=out_file)

Session 2:

library(dplyr)
library(ggplot2)
out_file = 'ggplot_obj.RDS'
p = loadRDS(out_file)
plot(p)

sessionInfo

R version 3.6.2 (2019-12-12)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS/LAPACK: /ebio/abt3_projects/Georg_animal_feces/envs/tidyverse/lib/libopenblasp-r0.3.7.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RColorBrewer_1.1-2 ggplot2_3.2.1      tidyr_1.0.0        dplyr_0.8.3       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3       plyr_1.8.5       pillar_1.4.3     compiler_3.6.2  
 [5] base64enc_0.1-3  tools_3.6.2      zeallot_0.1.0    digest_0.6.23   
 [9] uuid_0.1-2       jsonlite_1.6     evaluate_0.14    tibble_2.1.3    
[13] lifecycle_0.1.0  gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.2     
[17] IRdisplay_0.7.0  IRkernel_1.1     stringr_1.4.0    repr_1.0.2      
[21] withr_2.1.2      vctrs_0.2.1      grid_3.6.2       tidyselect_0.2.5
[25] glue_1.3.1       R6_2.4.1         pbdZMQ_0.3-3     purrr_0.3.3     
[29] farver_2.0.2     reshape2_1.4.3   magrittr_1.5     backports_1.1.5 
[33] scales_1.1.0     htmltools_0.4.0  assertthat_0.2.1 colorspace_1.4-1
[37] labeling_0.3     stringi_1.4.5    lazyeval_0.2.2   munsell_0.5.0   
[41] crayon_1.3.4    
@yutannihilation
Copy link
Member

Curious. I saw several people reported this error about data.frame(), but haven't figured out how to reproduce. Thanks for the reprex.

@thomasp85
Copy link
Member

There are a couple of things going on in your example that makes it hard to figure out if there are any problems in ggplot2 directly.

  • loadRDS() -> readRDS()
  • The pipe has precedence over plus so you are piping geom_bar() into saveRDS(), not the plot.
  • I cannot reproduce your error message by fixing the above issues.

Can you try to fix your example up. run it from a clean session and confirm that the error message persists

@yutannihilation
Copy link
Member

Ah, I too cannot reproduce the error... sorry

@thomasp85 thomasp85 added the reprex needs a minimal reproducible example label Jan 21, 2020
@yutannihilation
Copy link
Member

@nick-youngblut Could you provide a reproducible example? Otherwise, we have no choice but to close this issue.

@nick-youngblut
Copy link
Author

Sorry for the lack of reproducibility. It seems that the underlying cause was due to using saveRDS in one conda env running R and loading the saved object in a much different conda env running R (e.g., different R versions & package versions). I'm just going to try standardizing my R setups inside each conda env.

@yutannihilation
Copy link
Member

e.g., different R versions & package versions

Then, it might be because you saved the plot created with some old version of ggplot2 where the internal use of data.frame() was not restricted (now it is). I recommend you to use renv to fix the versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

3 participants