4

I'm getting an error using facet_wrap in ggplot2: "Error: predicate must be a closure or function pointer"

I do not have the problem when I use facet_grid.

This appears to be the same issue described in this post (I would have posted this as a comment, but don't have enough cred to do so. Also, the response seemed to attribute the issue to using the development version of ggplot. I'm using the tidyverse version installed from CRAN): ggplot2 facet_wrap Error: predicate must be a closure

Anybody else experiencing this? Thanks!

# Install from CRAN
# install.packages("tidyverse")
library(tidyverse)

mtcars %>%
  ggplot(aes(mpg,wt)) +
  geom_point() +
  facet_wrap(~cyl)
# This fails with message: 
# Error: `predicate` must be a closure or function pointer

mtcars %>%
  ggplot(aes(mpg,wt)) +
  geom_point() +
  facet_grid(cyl~carb)
# This works

# Session info
# R version 3.4.4 (2018-03-15)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows >= 8 x64 (build 9200)
# 
# Matrix products: default
# 
# locale:
#   [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
# [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
# [5] LC_TIME=English_United States.1252    
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] forcats_0.3.0      stringr_1.3.0      dplyr_0.7.4        purrr_0.2.4       
# [5] readr_1.1.1        tidyr_0.8.0        tibble_1.4.2       ggplot2_2.2.1.9000
# [9] tidyverse_1.2.1   
# 
Mycologica
  • 41
  • 2
  • 1
    I just ran your code with no error. Try restarting R, and maybe load just `ggplot2` and `dplyr`? – camille Apr 20 '18 at 15:43
  • 1
    Agree with @camille. No error here and you should apply basic degugging techniques to isolate the cause of your difficulties. If those difficuties persist, you should post a more complete description of your setup: versions of everything, and traceback() results. – IRTFM Apr 20 '18 at 15:55
  • I tried what Camille suggested and still experienced the same issue. I'll try more extensive debugging with traceback (I didn't know about that function), since it seems to be an issue with my particular configuration. Thanks for both of your suggestions. – Mycologica Apr 20 '18 at 16:31
  • Something to do with rlang? traceback() 2: rlang::flatten_if(facets_list, is.list) 1: facet_wrap(~cyl) – Mycologica Apr 20 '18 at 16:36
  • I removed tidyverse, rlang, ggplot, and dplyr using utils::remove.packages(). Reinstalled tidyverse from CRAN and I no longer get the error. Thanks! – Mycologica Apr 20 '18 at 16:54
  • I was running a dev version of ggplot2 and installing bleeding edge `rlang` version worked for me. – Roman Luštrik May 04 '18 at 11:01

0 Answers0