You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10 x64下R 4.2.2调用qgraph时R Studio崩溃求助

RStudio崩溃:qgraph包执行Fruchterman-Reingold布局时触发异常

环境:Windows 10 x64(版本19045),R 4.2.2

问题:调用qgraph包时RStudio会崩溃,执行第二个Fruchterman-Reingold布局代码时必然触发崩溃。此前相同代码在一个月前的其他项目中可正常运行。

已尝试的解决方案:调用x11()、切换至AGG图形设备,均无效。


会话信息

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8   
[3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.utf8    

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

other attached packages:
 [1] stringr_1.5.0        dplyr_1.1.0          qgraph_1.9.3        
 [4] geosphere_1.5-18     maps_3.4.1           circlize_0.4.15     
 [7] RColorBrewer_1.1-3   GGally_2.1.2         gridExtra_2.3       
[10] progress_1.2.2       ggrepel_0.9.3        ggplot2_3.4.1       
[13] vioplot_0.4.0        zoo_1.8-11           sm_2.2-5.7.1        
[16] scales_1.2.1         vegan_2.6-4          lattice_0.20-45     
[19] permute_0.9-7        igraph_1.4.0         sna_2.7-1           
[22] statnet.common_4.8.0 network_1.18.1       

loaded via a namespace (and not attached):
 [1] nlme_3.1-162        tools_4.2.2         backports_1.4.1    
 [4] utf8_1.2.3          R6_2.5.1            rpart_4.1.19       
 [7] Hmisc_4.8-0         mgcv_1.8-41         colorspace_2.0-3   
[10] nnet_7.3-18         withr_2.5.0         sp_1.6-0           
[13] mnormt_2.1.1        tidyselect_1.2.0    prettyunits_1.1.1  
[16] compiler_4.2.2      fdrtool_1.2.17      cli_3.5.0          
[19] htmlTable_2.4.1     checkmate_2.1.0     psych_2.2.9        
[22] quadprog_1.5-8      pbapply_1.7-0       pbivnorm_0.6.0     
[25] digest_0.6.31       foreign_0.8-84      rmarkdown_2.20     
[28] base64enc_0.1-3     jpeg_0.1-10         pkgconfig_2.0.3    
[31] htmltools_0.5.4     fastmap_1.1.0       htmlwidgets_1.6.1  
[34] rlang_1.0.6         GlobalOptions_0.1.2 rstudioapi_0.14    
[37] shape_1.4.6         generics_0.1.3      gtools_3.9.4       
[40] magrittr_2.0.3      Formula_1.2-5       interp_1.1-3       
[43] Matrix_1.5-3        Rcpp_1.0.10         munsell_0.5.0      
[46] fansi_1.0.4         abind_1.4-5         lifecycle_1.0.3    
[49] stringi_1.7.12      yaml_2.3.6          MASS_7.3-58.2      
[52] plyr_1.8.8          lavaan_0.6-14       parallel_4.2.2     
[55] crayon_1.5.2        deldir_1.0-6        splines_4.2.2      
[58] hms_1.1.2           knitr_1.42          pillar_1.8.1       
[61] corpcor_1.6.10      stats4_4.2.2        reshape2_1.4.4     
[64] glue_1.6.2          evaluate_0.20       latticeExtra_0.6-30
[67] data.table_1.14.8   png_0.1-8           vctrs_0.5.2        
[70] gtable_0.3.1        reshape_0.8.9       xfun_0.36          
[73] coda_0.19-4         glasso_1.11         survival_3.5-3     
[76] tibble_3.1.8        cluster_2.1.4       ellipsis_0.3.2 

触发崩溃的代码

# 第一行可正常执行
l <- qgraph.layout.fruchtermanreingold(edges, weights=edges$weight,vcount=vcount(graph_deu))

# 第二行执行时必然触发崩溃
lm <- qgraph.layout.fruchtermanreingold(edges,vcount=vcount(graph_deu), area=8*(vcount(graph_deu)^2),repulse.rad=(vcount(graph_deu)^3.1))

排查建议

  • 检查数据差异:对比当前项目与之前正常运行项目的edges和graph_deu数据,重点关注节点数量、边的权重范围。第二个布局中repulse.rad=(vcount(graph_deu)^3.1)如果节点数较多,会生成极大的排斥半径值,可能引发内存溢出或计算逻辑崩溃
  • 调整qgraph版本:当前使用qgraph_1.9.3,尝试安装旧版本(如1.9.2)或最新开发版,排查版本兼容性问题
  • 隔离测试:新建干净R脚本,仅加载qgraph包,用简化的测试网络数据运行这两行布局代码,排除其他加载包的依赖冲突
  • 监控内存占用:执行代码时打开任务管理器,查看RStudio的内存使用情况,如果内存占用飙升超过系统可用内存,会直接导致崩溃,可尝试减少节点数量测试
  • 避开RStudio:直接使用RGui运行代码,排查是否是RStudio的图形渲染模块导致的崩溃

内容的提问来源于stack exchange,提问作者srrein

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 08:12:04