trevorld / ggpattern

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

"image" pattern bug with 'type = "tile"' #37

Closed dmongin closed 2 years ago

dmongin commented 3 years ago

When trying to reproduce a vignette example:

logo_filename   <- system.file("img", "Rlogo.png" , package="png")
magpie_filename <- system.file("img", "magpie.jpg", package="ggpattern")
bug_filename    <- system.file("img", "bug.jpg"   , package="ggpattern")

library(dplyr)
library(ggpattern)

df1 <- tibble(
  trt      = c("a", "b", "c"),
  outcome  = c(2.3, 1.9, 3.2),
  gravity  = c('South', 'North', 'West'),
  filltype = c('squish', 'fit' , 'expand'),
  scale    = c(1, 2, 0.5),
  filename = c(logo_filename, magpie_filename, bug_filename)
)

library(ggplot2)

ggplot(df1, aes(trt, outcome)) +
  geom_col_pattern(
    aes(
      fill             = trt,
      pattern_filename = I(filename)
    ),
    pattern          = 'image',
    pattern_type     = 'tile',
    pattern_scale    = -1,
    colour           = 'black'
  ) +
  theme_bw(15) +
  labs(
    title    = "ggpattern::geom_col_pattern()",
    subtitle = "pattern = 'image', pattern_type = 'tile',\npattern_scale = -1"
  ) +
  theme(legend.position = 'none') +
  coord_fixed(ratio = 1)

I get the following error:

ParamŠtre non valide - 122x313
Erreur dans magick_image_readpath(path, density, depth, strip, defines) : 
  rsession.exe: UnableToOpenBlob `C:\Users\denis\AppData\Local\Temp\RtmpmGhtJA\filef8074d476d2.png': No such file or directory @ error/blob.c/OpenBlob/2924

I updated magick, but it did not solve the pb.

Here is my session info:

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

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] magick_2.7.2    ggplot2_3.3.3   ggpattern_0.1.3 dplyr_1.0.6    

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1   xfun_0.23          purrr_0.3.4        sf_0.9-8           colorspace_2.0-1  
 [6] vctrs_0.3.8        generics_0.1.0     htmltools_0.5.1.1  yaml_2.2.1         utf8_1.2.1        
[11] rlang_0.4.11       gridGeometry_0.2-0 e1071_1.7-7        pillar_1.6.1       glue_1.4.2        
[16] withr_2.4.2        DBI_1.1.1          lifecycle_1.0.0    munsell_0.5.0      gtable_0.3.0      
[21] evaluate_0.14      labeling_0.4.2     knitr_1.33         fastmap_1.1.0      class_7.3-19      
[26] fansi_0.4.2        Rcpp_1.0.6         KernSmooth_2.23-20 scales_1.1.1       classInt_0.4-3    
[31] cachem_1.0.5       farver_2.1.0       png_0.1-7          digest_0.6.27      stringi_1.6.1     
[36] polyclip_1.10-0    grid_4.1.0         cli_2.5.0          tools_4.1.0        magrittr_2.0.1    
[41] proxy_0.4-25       tibble_3.1.2       crayon_1.4.1       pkgconfig_2.0.3    ellipsis_0.3.2    
[46] lubridate_1.7.10   assertthat_0.2.1   rmarkdown_2.8      rstudioapi_0.13    R6_2.5.0          
[51] units_0.7-1        compiler_4.1.0  
dmongin commented 3 years ago

The image exists

> logo_filename
[1] "C:/Users/denis/Documents/R/win-library/4.1/png/img/Rlogo.png"

and indeed C:\Users\denis\AppData\Local\Temp\RtmpmGhtJA\filef8074d476d2.png does not exist. I do not understand why magick is trying to get an image that does not exist. I tried running R as admin, it did not solve the pb either.

trevorld commented 3 years ago
trevorld commented 3 years ago

It would be great if someone who has an affected platform (unfortunately can't reproduce this on mine) can extract a minimal reproducible example (cutting out {ggpattern}) and submit it upstream to {magick} (who in turn might need to pass it to the magick project) so this could be fixed.

ndfooz commented 2 years ago

It would be great if someone who has an affected platform (unfortunately can't reproduce this on mine) can extract a minimal reproducible example (cutting out {ggpattern}) and submit it upstream to {magick} (who in turn might need to pass it to the magick project) so this could be fixed.

I have the same issue when running the exemplary code

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# filenames of images
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
logo_filename   <- system.file("img", "Rlogo.png" , package="png")
magpie_filename <- system.file("img", "magpie.jpg", package="ggpattern")
bug_filename    <- system.file("img", "bug.jpg"   , package="ggpattern")

seamless1 <- system.file("img", "seamless1.jpg"   , package="ggpattern")
seamless2 <- system.file("img", "seamless2.jpg"   , package="ggpattern")
seamless3 <- system.file("img", "seamless3.jpg"   , package="ggpattern")

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Plotting data
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
df1 <- data.frame(
  trt      = c("a", "b", "c"), 
  outcome  = c(2.3, 1.9, 3.2),
  gravity  = c('South', 'North', 'West'),
  filltype = c('squish', 'fit' , 'expand'),
  scale    = c(1, 2, 0.5),
  filename = c(logo_filename, magpie_filename, bug_filename),
  stringsAsFactors = FALSE
)
ggplot(df1, aes(trt, outcome)) +
  geom_col_pattern(
    aes(
      fill            = trt,
      pattern_gravity = I(gravity),
      pattern_scale   = I(scale)
    ), 
    pattern          = 'image', 
    pattern_filename = logo_filename,
    pattern_type     = 'none',
    colour           = 'black'
  )

What do you mean precisely by submitting an example upstream, cutting out {ggpattern}? I would not know how to reproduce this error outside of the ggpattern context.

trevorld commented 2 years ago

{ggpattern} calls {gridpattern} calls {magick}. There should be a sequence of underlying R commands that reproduce this error that only require {magick} and not {ggpattern} nor {gridpattern}. The {magick} maintainer is much more likely to solve the issue if we give them a minimal, reproducible example. They probably are not going to disentangle the {ggpattern} -> {gridpattern} -> {magick} code themselves... Figuring out that underlying sequence would involve reading {gridpattern} code and writing {magick} code:

1) Reproduce the error using just gridpattern::grid.pattern_image() instead of {ggpattern} 2) Re-write relevant grid.pattern_image() logic into minimal, reproducible {magick} code

Note that example works fine on our personal machines, only a subset of users are affected and we're not sure why. Hard to fix a bug we can't directly see ourselves.

trevorld commented 2 years ago