vegandevs / vegan

R package for community ecologists: popular ordination methods, ecological null models & diversity analysis
https://vegandevs.github.io/vegan/
GNU General Public License v2.0
456 stars 98 forks source link

Running rarecurve() crashes vscode in querying par() #654

Closed maartenciers closed 5 months ago

maartenciers commented 5 months ago

When I'm Running:

size = min(colSums2(assay(tseObj)))
ASVs = t(assay(tseObj,"counts")[])
rare_df = rarecurve(ASVs, sample = size, tidy = TRUE, step = 10)

It crashes my terminal in vscode. I can't see the error as it crashes to quickly and the terminal disappears.

SessionInfo:

> sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: x86_64-redhat-linux-gnu
Running under: AlmaLinux 9.4 (Seafoam Ocelot)

Matrix products: default
BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP;  LAPACK version 3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Brussels
tzcode source: system (glibc)

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

other attached packages:
 [1] miaViz_1.12.0                   ggraph_2.2.1                   
 [3] ggplot2_3.5.1                   vegan_2.6-7                    
 [5] lattice_0.22-6                  permute_0.9-7                  
 [7] tibble_3.2.1                    writexl_1.5.0                  
 [9] readxl_1.4.3                    mia_1.13.18                    
[11] MultiAssayExperiment_1.30.1     TreeSummarizedExperiment_2.12.0
[13] Biostrings_2.72.0               XVector_0.44.0                 
[15] SingleCellExperiment_1.26.0     SummarizedExperiment_1.34.0    
[17] Biobase_2.64.0                  GenomicRanges_1.56.0           
[19] GenomeInfoDb_1.40.0             IRanges_2.38.0                 
[21] S4Vectors_0.42.0                BiocGenerics_0.50.0            
[23] MatrixGenerics_1.16.0           matrixStats_1.3.0              
[25] phyloseq_1.48.0                

loaded via a namespace (and not attached):
  [1] rstudioapi_0.16.0           jsonlite_1.8.8             
  [3] magrittr_2.0.3              ggbeeswarm_0.7.2           
  [5] farver_2.1.2                nloptr_2.0.3               
  [7] rmarkdown_2.27              fs_1.6.4                   
  [9] zlibbioc_1.50.0             vctrs_0.6.5                
 [11] multtest_2.60.0             minqa_1.2.7                
 [13] memoise_2.0.1               DelayedMatrixStats_1.26.0  
 [15] ggtree_3.12.0               base64enc_0.1-3            
 [17] htmltools_0.5.8.1           S4Arrays_1.4.1             
 [19] BiocNeighbors_1.22.0        cellranger_1.1.0           
 [21] Rhdf5lib_1.26.0             gridGraphics_0.5-1         
 [23] SparseArray_1.4.5           Formula_1.2-5              
 [25] rhdf5_2.48.0                htmlwidgets_1.6.4          
 [27] sandwich_3.1-0              plyr_1.8.9                 
 [29] DECIPHER_3.0.0              zoo_1.8-12                 
 [31] cachem_1.1.0                igraph_2.0.3               
 [33] lifecycle_1.0.4             iterators_1.0.14           
 [35] pkgconfig_2.0.3             rsvd_1.0.5                 
 [37] Matrix_1.7-0                R6_2.5.1                   
 [39] fastmap_1.2.0               GenomeInfoDbData_1.2.12    
 [41] aplot_0.2.2                 digest_0.6.35              
 [43] ggnewscale_0.4.10           colorspace_2.1-0           
 [45] patchwork_1.2.0             scater_1.32.0              
 [47] irlba_2.3.5.1               Hmisc_5.1-2                
 [49] beachmat_2.20.0             fansi_1.0.6                
 [51] polyclip_1.10-6             httr_1.4.7                 
 [53] abind_1.4-5                 mgcv_1.9-1                 
 [55] compiler_4.4.0              withr_3.0.0                
 [57] htmlTable_2.4.2             backports_1.4.1            
 [59] BiocParallel_1.38.0         viridis_0.6.5              
 [61] DBI_1.2.2                   ggforce_0.4.2              
 [63] MASS_7.3-60.2               DelayedArray_0.30.1        
 [65] biomformat_1.32.0           bluster_1.14.0             
 [67] tools_4.4.0                 vipor_0.4.7                
 [69] foreign_0.8-86              beeswarm_0.4.0             
 [71] ape_5.8                     nnet_7.3-19                
 [73] glue_1.7.0                  nlme_3.1-164               
 [75] rhdf5filters_1.16.0         grid_4.4.0                 
 [77] checkmate_2.3.1             cluster_2.1.6              
 [79] reshape2_1.4.4              ade4_1.7-22                
 [81] lpSolve_5.6.20              generics_0.1.3             
 [83] gtable_0.3.5                mediation_4.5.0            
 [85] tidyr_1.3.1                 data.table_1.15.4          
 [87] tidygraph_1.3.1             BiocSingular_1.20.0        
 [89] ScaledMatrix_1.12.0         utf8_1.2.4                 
 [91] ggrepel_0.9.5               foreach_1.5.2              
 [93] pillar_1.9.0                stringr_1.5.1              
 [95] yulab.utils_0.1.4           splines_4.4.0              
 [97] tweenr_2.0.3                dplyr_1.1.4                
 [99] treeio_1.28.0               survival_3.6-4             
[101] tidyselect_1.2.1            DirichletMultinomial_1.46.0
[103] scuttle_1.14.0              knitr_1.46                 
[105] gridExtra_2.3               xfun_0.44                  
[107] graphlayouts_1.1.1          stringi_1.8.4              
[109] UCSC.utils_1.0.0            ggfun_0.1.4                
[111] boot_1.3-30                 lazyeval_0.2.2             
[113] evaluate_0.23               codetools_0.2-20           
[115] ggplotify_0.1.2             cli_3.6.2                  
[117] rpart_4.1.23                munsell_0.5.1              
[119] Rcpp_1.0.12                 parallel_4.4.0             
[121] sparseMatrixStats_1.16.0    lme4_1.1-35.3              
[123] mvtnorm_1.2-5               decontam_1.24.0            
[125] viridisLite_0.4.2           tidytree_0.4.6             
[127] scales_1.3.0                purrr_1.0.2                
[129] crayon_1.5.2                rlang_1.1.3 
gavinsimpson commented 5 months ago

What are the dimensions of ASVs? I suspect they are pretty big and that's resulting in some memory mangling, but it would help to know how big these things are.

maartenciers commented 5 months ago

They are actually not that big as you would expect.

> dim(ASVs)
[1]    9 2321
jarioksa commented 5 months ago

This is not reproducible and there is no information to help in guessing. If you are in Linux, can you run this command in shell (bash, zsh, csh what ever) to see the error message.

It is surprising that this crashes the window. Such crashes can happen when we use compiled code, but rarecurve (and rarefy it calls) are both implemented in pure R.

maartenciers commented 5 months ago

I've tried it but I have to say I find it quite weird that it works in terminal but not in vscode terminal. So I guess it's not package related then... Sorry to bother

jarioksa commented 5 months ago

Before running the command in vscode, say debugonce(rarecurve): this steps through the function line by line. Then you can at least see which line crashes even if you cannot see the error message.

maartenciers commented 5 months ago

This was very helpful! my R crashes when running par() so either this is 4.4.0 related or something else.

jarioksa commented 5 months ago

The manual says ?par

Each device has its own set of graphical parameters. If the current device is the null device, ‘par’ will open a new device before querying/setting parameters. (What device is controlled by ‘options("device")’.)

So it must be how vscode sets (or does not set) its graphical device.

Does it help if you say plot(1) before the call? This should open the graphical device, andpar() should be able to read its graphical parameters.

maartenciers commented 5 months ago

You are correct it works after running plot(1) . That would explain why it sometimes didn't crash. Thank you so much!