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

VS Code运行含R代码的Quarto文件时出现invalid permissions段错误

使用VS Code + httpgd运行R代码时触发段错误的问题

在VS Code中运行包含R代码的.qmd文件,启用r.plot.useHttpgd绘制图形时,部分场景会触发caught segfault错误。当不使用httpgd(输出为.png文件)或在RStudio中运行时,代码完全正常。

可复现示例

library(spatstat)

plot(amacrine) # 此代码运行正常
plot(unmark(amacrine)) # 此处出现崩溃

错误信息

*** caught segfault ***
address 0x0, cause 'invalid permissions'

Traceback:
 1: dev.capabilities()
 2: default.symap.points(unmark(x), ..., chars = chars, cols = cols)
 3: plot.ppp(unmark(amacrine))
 4: plot(unmark(amacrine))

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

环境信息

> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.6.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/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] spatstat_3.0-6         spatstat.linnet_3.1-1  spatstat.model_3.2-4  
[4] rpart_4.1.19           spatstat.explore_3.2-1 nlme_3.1-160          
[7] spatstat.random_3.1-5  spatstat.geom_3.2-1    spatstat.data_3.0-1   

loaded via a namespace (and not attached):
 [1] lattice_0.20-45       deldir_1.0-9          grid_4.2.2            
 [4] jsonlite_1.8.7        tensor_1.5            rlang_1.1.1           
 [7] cli_3.6.1             goftest_1.2-3         Matrix_1.5-4.1        
[10] spatstat.utils_3.0-3  splines_4.2.2         polyclip_1.10-4       
[13] abind_1.4-5           compiler_4.2.2        spatstat.sparse_3.0-2
[16] mgcv_1.8-41   

问题分析与解决方案

这不是VS Code本身的问题,而是httpgd图形设备与spatstat包中无标记点对象绘图逻辑的兼容性问题。从报错栈可见,崩溃发生在dev.capabilities()调用时,推测是httpgd在处理无标记ppp对象的绘图请求时,内部存在空指针引用错误。

临时解决方法

在绘制无标记ppp对象时,临时禁用httpgd:

# 临时切换到默认图形设备
options(r.plot.useHttpgd = FALSE)
plot(unmark(amacrine))
# 若需要继续使用httpgd,执行下方代码
# options(r.plot.useHttpgd = TRUE)

长期解决建议

  1. 更新httpgd包到最新版本,新版本可能修复了该兼容性问题;
  2. 更新spatstat包到最新版本,查看是否优化了绘图逻辑;
  3. 向httpgd包开发者提交bug报告,提供可复现代码与环境信息。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 17:42:35