Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rstudio crashes when using ggsave() to write .tiff images #5304

Closed
RuiyuRayWang opened this issue Nov 17, 2021 · 3 comments
Closed

Rstudio crashes when using ggsave() to write .tiff images #5304

RuiyuRayWang opened this issue Nov 17, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@RuiyuRayWang
Copy link

RuiyuRayWang commented Nov 17, 2021

When using ggsave() tiff device saving Seurat plots, Rstudio crashed:
R Session Aborted: R encountered a fatal error. The session was terminated.

Yesterday it was working fine. This only happens today.
This happens only on my mac (Catalina 10.15.7). Testing on ubuntu (18.04 LTS) everything works fine.

Searched for recently raised issues and found a similar one #4554 which is resolved by Rstudio upgrade. I tried upgrading Rstudio to 1.v1.4.1717-3 Preview but the issue persisted.

library(Seurat)
library(ggplot2)

DotPlot(pbmc_small, 
        features = "MS4A1")
ggsave(filename = "test.png", device = "png")  # Works fine
ggsave(filename = "test.tiff", device = "tiff") # Crash

Plot functions I've tested and crashed include: DotPlot(), RidgePlot(), VlnPlot(), FeaturePlot(), DimPlot(), FeatureScatter()

# All crashed when invoking ggsave("test.tiff")
DotPlot(pbmc_small, 
        features = "MS4A1")
RidgePlot(pbmc_small, 
        features = "MS4A1")
VlnPlot(pbmc_small,
        features = "MS4A1")
FeaturePlot(pbmc_small,
            features = "MS4A1")
DimPlot(pbmc_small,
        features = "MS4A1")
FeatureScatter(pbmc_small,
               feature1 = "MS4A1", feature2 = "CD79B")

DoHeatmap() is unaffected

library(tidyverse)
pbmc_small <- pbmc_small %>% NormalizeData() %>% ScaleData()
DoHeatmap(pbmc_small, features = VariableFeatures(pbmc_small))
ggsave(filename = "test.tiff", device = "tiff") # Success

This does not look like a ggplot issue as plots generated by ggplot are unaffected. Only Seurat generated plots are affected.

ggplot(mtcars, aes(x=mpg, y=cyl)) +
  geom_point()
ggsave("test.tiff") # Works fine
> sessionInfo()

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] ggplot2_3.3.5      SeuratObject_4.0.2 Seurat_4.0.5      

loaded via a namespace (and not attached):
  [1] nlme_3.1-153          spatstat.sparse_2.0-0 matrixStats_0.61.0    RcppAnnoy_0.0.19      RColorBrewer_1.1-2   
  [6] httr_1.4.2            sctransform_0.3.2     tools_4.0.2           utf8_1.2.2            R6_2.5.1             
 [11] irlba_2.3.3           rpart_4.1-15          KernSmooth_2.23-20    uwot_0.1.10           mgcv_1.8-38          
 [16] DBI_1.1.1             lazyeval_0.2.2        colorspace_2.0-2      withr_2.4.2           tidyselect_1.1.1     
 [21] gridExtra_2.3         compiler_4.0.2        plotly_4.10.0         scales_1.1.1          lmtest_0.9-38        
 [26] spatstat.data_2.1-0   ggridges_0.5.3        pbapply_1.5-0         goftest_1.2-3         stringr_1.4.0        
 [31] digest_0.6.28         spatstat.utils_2.2-0  rmarkdown_2.11        pkgconfig_2.0.3       htmltools_0.5.2      
 [36] parallelly_1.28.1     fastmap_1.1.0         htmlwidgets_1.5.4     rlang_0.4.12          shiny_1.7.1          
 [41] generics_0.1.1        zoo_1.8-9             jsonlite_1.7.2        ica_1.0-2             dplyr_1.0.7          
 [46] magrittr_2.0.1        patchwork_1.1.1       Matrix_1.3-4          Rcpp_1.0.7            munsell_0.5.0        
 [51] fansi_0.5.0           abind_1.4-5           reticulate_1.22       lifecycle_1.0.1       stringi_1.7.5        
 [56] yaml_2.2.1            MASS_7.3-54           Rtsne_0.15            plyr_1.8.6            grid_4.0.2           
 [61] parallel_4.0.2        listenv_0.8.0         promises_1.2.0.1      ggrepel_0.9.1         crayon_1.4.2         
 [66] deldir_1.0-6          miniUI_0.1.1.1        lattice_0.20-45       cowplot_1.1.1         splines_4.0.2        
 [71] tensor_1.5            knitr_1.36            pillar_1.6.4          igraph_1.2.7          spatstat.geom_2.3-0  
 [76] future.apply_1.8.1    reshape2_1.4.4        codetools_0.2-18      leiden_0.3.9          glue_1.4.2           
 [81] evaluate_0.14         data.table_1.14.2     png_0.1-7             vctrs_0.3.8           httpuv_1.6.3         
 [86] polyclip_1.10-0       gtable_0.3.0          RANN_2.6.1            purrr_0.3.4           spatstat.core_2.3-1  
 [91] tidyr_1.1.4           scattermore_0.7       future_1.23.0         assertthat_0.2.1      xfun_0.27            
 [96] mime_0.12             xtable_1.8-4          later_1.3.0           survival_3.2-13       viridisLite_0.4.0    
[101] tibble_3.1.5          cluster_2.1.2         globals_0.14.0        fitdistrplus_1.1-6    ellipsis_0.3.2       
[106] ROCR_1.0-11
@RuiyuRayWang RuiyuRayWang added the bug Something isn't working label Nov 17, 2021
@RuiyuRayWang
Copy link
Author

Update:

Encountered the same issue without using Seurat but using cowplot with ggpubr. I guess cowplot is the source of the issue here?

Also tried save_plot() to replace ggsave() but the issue persisted. Guess I'll close this issue and post it to cowplot page.

@wibeasley
Copy link

We had this problem too with a vanilla ggplot graph. We got around it with grDevices::tiff() and dev.off().

cc: @deshea

@RuiyuRayWang
Copy link
Author

RuiyuRayWang commented Dec 1, 2021

We had this problem too with a vanilla ggplot graph. We got around it with grDevices::tiff() and dev.off().

cc: @deshea

Thanks @wibeasley, grDevices works!

As pointed out by @clauswilke, this is an ragg issue. Switching to grDevices resolved the problem.

library(Seurat)
library(ggplot2)

DotPlot(pbmc_small, 
        features = "MS4A1")
ggsave("test.tiff", device = grDevices::tiff)

Alternatively

grDevices::tiff(filename = "test.tiff", bg = "transparent")
DotPlot(pbmc_small, 
        features = "MS4A1")
dev.off()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants