Simple plot crashes RStudio 1.4 dailies

The second plot in the following code reliably crashes the daily builds of RStudio 1.4 (builds 708 and 834) for me. It works fine in 1.3.

library(tidyverse)
library(palmerpenguins)

# labels of similar size
label1 = rep('abcdefg:1234567', 7) %>% paste0(collapse='\n')
summ = summary(select(penguins, bill_depth_mm)) %>% paste0(collapse = '\n')

# works fine
ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = label1)

# crashes RStudio
ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = summ)
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

other attached packages:
 [1] palmerpenguins_0.1.0 forcats_0.5.0        stringr_1.4.0        dplyr_1.0.1          purrr_0.3.4          readr_1.3.1         
 [7] tidyr_1.1.1          tibble_3.0.3         ggplot2_3.3.2        tidyverse_1.3.0     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5       cellranger_1.1.0 pillar_1.4.6     compiler_4.0.2   dbplyr_1.4.4     tools_4.0.2      jsonlite_1.7.0  
 [8] lubridate_1.7.9  lifecycle_0.2.0  gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.7      reprex_0.3.0     cli_2.0.2       
[15] DBI_1.1.0        rstudioapi_0.11  yaml_2.2.1       haven_2.3.1      withr_2.2.0      xml2_1.3.2       httr_1.4.1      
[22] fs_1.4.1         generics_0.0.2   vctrs_0.3.4      hms_0.5.3        grid_4.0.2       tidyselect_1.1.0 glue_1.4.2      
[29] R6_2.4.1         fansi_0.4.1      readxl_1.3.1     modelr_0.1.8     blob_1.2.1       magrittr_1.5     backports_1.1.8 
[36] scales_1.1.1     ellipsis_0.3.1   rvest_0.3.5      assertthat_0.2.1 colorspace_1.4-1 stringi_1.4.6    munsell_0.5.0   
[43] broom_0.7.0      crayon_1.3.4    
1 Like

I tried your code on two different machines (one macOS, one Windows) but wasn't able to reproduce the crash (on RStudio 1.4.842). Does it still reproduce for you on that build? :-/ Do you have RStudio's crash reporting enabled?

Yes, it still reproduces for me on 1.4.842.
2020-09-18_14-35-51

I have crash reporting enabled, but I'm not sure it gets to that point because the session aborts.

The crash seems to be exclusive to the AGG graphics backend when the last character of a line in the label is a space preceded by any non-space character. It does not occur with the Windows and Cairo backends.

library(tidyverse)
library(palmerpenguins)

# labels of similar size
label1 = rep('abcdefg:1234567', 7) %>% paste0(collapse='\n')
label2 = rep('abcdefg:123456 ', 7) %>% paste0(collapse='\n')
label3 = rep(' abcdef:1234567', 7) %>% paste0(collapse='\n')
summ = summary(select(penguins, bill_depth_mm)) %>% paste0(collapse = '\n')
summ2 = summary(select(penguins, bill_depth_mm)) %>% str_remove_all(' +$') %>% paste0(collapse = '\n')

# these 5 plots work fine
ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = label1)

ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = label3)

ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = summ2)

ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = summ2 %>% sprintf(' \n%s', .))

ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = summ2 %>% sprintf('  \n%s', .))

# these 3 plots crash RStudio with AGG backend (trailing space(s) in label)
ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = label2)

ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = summ)

ggplot(penguins, aes(x = bill_depth_mm)) +
  geom_histogram(bins = 100) +
  annotate('label', x = Inf, y = Inf, hjust = 1, vjust = 1, label = summ2 %>% sprintf('1 \n%s', .))

Thanks, that's helpful, but I can't reproduce even with AGG, so there must be some other variable in play...

What version of the ragg package do you have?

Does this code produce plots for you w/o crashing when you use ragg outside of RStudio (i.e. in the plain R GUI)?

Ok, looks like updating ragg to 0.3.1 fixed it. I was on 0.2.0 before. Thanks!

Whew, glad that's all it was. Thanks for following up!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.