trevorld / ggpattern

ggplot geoms with pattern fills
https://trevorldavis.com/R/ggpattern/dev/
Other
361 stars 18 forks source link

[BUG] ggpattern not working under VS Code #90

Closed toorukt closed 2 years ago

toorukt commented 2 years ago

Bug description

I was trying to fill in a bar plot with patterns and then found this amazing package. However, it seems not working with VS Code, by showing up a "Segmentation fault" which I have no idea what it is. I've attached a screenshot to display the problem.

スクリーンショット 2022-10-10 21 14 20

BTW, I ran same codes under R studio and it did work, so I suspect there might be some conflicts with httpgd (the package VS Code used to display plot) or something else. Also, the problem has been reproduced under Macs and ubuntu VPS (connected through SSH by VS Code).

Minimal, reproducible example

library(ggplot2)
library(ggpattern)

df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1))

ggplot(df) +
  geom_col_pattern(
    aes(level, outcome, pattern_fill = level),
    pattern = "stripe",
    fill    = "white",
    colour  = "black"
  ) +
  theme_bw(18) +
  theme(legend.position = "none") +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern = 'stripe'"
  ) +
  coord_fixed(ratio = 1 / 2)

Session info

R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS, RStudio 0

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
  LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  cachem_1.0.6       class_7.3.20       classInt_0.4.8     cli_3.4.1          colorspace_2.0.3   DBI_1.1.3          digest_0.6.29     
  e1071_1.7.11       fansi_1.0.3        farver_2.1.1       fastmap_1.1.0      ggpattern_1.0.0    ggplot2_3.3.6      glue_1.6.2        
  graphics_4.2.1     grDevices_4.2.1    grid_4.2.1         gridpattern_1.0.1  gtable_0.3.1       isoband_0.2.6      KernSmooth_2.23.20
  labeling_0.4.2     lattice_0.20.45    lifecycle_1.0.3    magrittr_2.0.3     MASS_7.3.58.1      Matrix_1.5.1       memoise_2.0.1     
  methods_4.2.1      mgcv_1.8.40        munsell_0.5.0      nlme_3.1.159       pillar_1.8.1       pkgconfig_2.0.3    png_0.1.7         
  proxy_0.4.27       R6_2.5.1           RColorBrewer_1.1.3 Rcpp_1.0.9         rlang_1.0.6        s2_1.1.0           scales_1.2.1      
  sf_1.0.8           splines_4.2.1      stats_4.2.1        tibble_3.1.8       tools_4.2.1        units_0.8.0        utf8_1.2.2        
  utils_4.2.1        vctrs_0.4.2        viridisLite_0.4.1  withr_2.5.0        wk_0.6.0          
trevorld commented 2 years ago

I installed VS Code on an Ubuntu server and couldn't reproduce your error. The chart from your example showed up fine using R 4.2.1:

Screenshot_2022-10-10_09-03-45

You could try explicitly telling {ggpattern} your graphic device's R 4.1 graphic feature support since your weird bug happens when it tries to detect it:

options(ggpattern_use_R4.1_features = FALSE) # unsure of graphics device support
options(ggpattern_use_R4.1_features = TRUE) # sure that device supports them
trevorld commented 2 years ago

The traceback indicates you had a SegFault when grDevices::dev.capabilities() was called. What happens when you just call that in VS Code?

grDevices::dev.capabilities()
toorukt commented 2 years ago

Thanks for the prompt reply! That's wired. I check it using another ubuntu VPS and my friend's M2 MacBook Air, it crashed again.

for the grDevices::dev.capabilities() code, if I ran it by a normal user, error happened again (see the screenshot)

スクリーンショット 2022-10-11 9 48 34

However, if I ran it by root user, it seems fine by showing the following Info:

grDevices::dev.capabilities()
$semiTransparency
[1] TRUE

$transparentBackground
[1] "semi"

$rasterImage
[1] "yes"

$capture
[1] FALSE

$locator
[1] FALSE

$events
character(0)

$patterns
[1] "LinearGradient" "RadialGradient" "TilingPattern" 

$clippingPaths
[1] TRUE

$masks
[1] "alpha"     "luminance"

$compositing
 [1] "multiply"    "screen"      "overlay"     "darken"      "lighten"    
 [6] "color.dodge" "color.burn"  "hard.light"  "soft.light"  "difference" 
[11] "exclusion"  

$transformations
[1] TRUE

$paths
[1] TRUE

I'm not familiar with code and technical stuff so I am wondering what the problem is.🤣

trevorld commented 2 years ago