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', .))