trevorld / ggpattern

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

[BUG] Incompatibility between VSCode/radian and `ggpattern` #99

Closed Haclio closed 1 year ago

Haclio commented 1 year ago

Every time I try to render a ggplot2 object in the VSCode viewer in which ggpattern has been used, the R terminal radian closes abruptly. I can't discount a problem with VSCode itself, but ggpattern is the only package I have trouble with, and I've tried in RStudio and it works.

VSCode returns an error : The terminal process "C:\Users\XXXXXX\AppData\Local\Programs\Python\Python311\Scripts\radian.exe '--no-save', '--no-restore'" exited with code: 3221225477. A quick search online tells me this error is due to something related to access violations, but why only ggpattern ? I'm just starting to use VSCode so I'm afraid I don't have much else to say for now. I'll be happy to help if anything else is needed.

Reproducible example

library(ggpattern)
ggplot(mtcars, aes(x = cyl)) + geom_bar_pattern()

(yes, that's all it takes)

Session info

Please enter here the results of xfun::session_info("ggpattern")

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044), RStudio 0

Locale: LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252 LC_NUMERIC=C                   LC_TIME=French_France.1252    

Package version:
  cachem_1.0.7       class_7.3.20       classInt_0.4.9     cli_3.6.0          colorspace_2.1.0   DBI_1.1.3          e1071_1.7.13       fansi_1.0.4        farver_2.1.1
  fastmap_1.1.1      ggpattern_1.0.1    ggplot2_3.4.1      glue_1.6.2         graphics_4.2.2     grDevices_4.2.2    grid_4.2.2         gridpattern_1.0.2  gtable_0.3.1
  isoband_0.2.7      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.2      mgcv_1.8.41        munsell_0.5.0      nlme_3.1.160       pillar_1.8.1       pkgconfig_2.0.3    png_0.1.8          proxy_0.4.27       R6_2.5.1
  RColorBrewer_1.1.3 Rcpp_1.0.10        rlang_1.0.6        s2_1.1.2           scales_1.2.1       sf_1.0.12          splines_4.2.2      stats_4.2.2        tibble_3.1.8
  tools_4.2.2        units_0.8.1        utf8_1.2.3         utils_4.2.2        vctrs_0.5.2        viridisLite_0.4.1  withr_2.5.0        wk_0.7.2
trevorld commented 1 year ago

Not reproducible for me. If I install the .deb package for VSCode from https://code.visualstudio.com and then when prompted install the recommended R plugins then your example (with the addition of library("ggplot2")) works fine on my platform (Ubuntu Linux).

Perhaps this is a duplicate of https://github.com/coolbutuseless/ggpattern/issues/90

What happens when you call grDevices::dev.capabilities() in your VSCode R terminal?

If so you may be able to sidestep this by setting options(ggpattern_use_R4.1_features = FALSE) or options(ggpattern_use_R4.1_features = TRUE).

Haclio commented 1 year ago

Hi, thanks for the quick response.

I should have added that I'm on Windows, my apologies for that.

grDevices::dev.capabilities() closes my R terminal, without any error code or message.

Both options(ggpattern_use_R4.1_features = FALSE) or options(ggpattern_use_R4.1_features = TRUE) make ggplot render the patterns without error, so thanks for that. I don't know what these particular features do so, is one of them preferred over the other ?

trevorld commented 1 year ago

I don't know what these particular features do so, is one of them preferred over the other ?

options(ggpattern_use_R4.1_features = TRUE) tells {gridpattern} (used by {ggpattern}) to render certain patterns using features which only a subset of R graphics devices support. If the R graphics devices do not support these features and this is an affected pattern then the pattern will be rendered incorrectly but if the R graphics device does support these features it should render faster and more sharply.

options(ggpattern_use_R4.1_features = FALSE) tells {gridpattern} (used by {ggpattern}) to render patterns using a rasterized fallback which should work on more graphics devices but will render slower and may look more "pixelated".

{gridpattern} uses grDevices::dev.capabilities() to tell if your active graphics devices supports these features but for some weird reason on a subset of VSCode implementations this causes it to close or segfault.

I'm closing this issue because this doesn't seem to be a bug with {ggpattern}.

trevorld commented 1 year ago

@toorukt or @Haclio , if you can reproduce your grDevices::dev.capabilities() segfaults-when-called-within-VSCode issue with the development version of R (ake "R devel") this bug may be worth reporting upstream to the core R team. Unfortunately I can't reproduce this issue myself.

If you can reproduce this in R devel one way to report is to post to the R-devel mailing list: https://stat.ethz.ch/mailman/listinfo/r-devel