我发现在回调中使用 igraph 库对获取/设置顶点属性的任何调用都会导致 R 中的段错误。例如,来自一段代码的微不足道的回调:
dfsCallBack <- function(graph, data, extra) {
cat("in:", paste(collapse=", ", data), "\n")
distFromRoot <- data[2]
vertexID <- data[1]
set.vertex.attribute(graph, 0, name = 'color', value = 'blue')
FALSE
}
graph.dfs(g, 1, in.callback = dfsCallBack)
产生此错误:
graph.dfs(g, 1, in.callback = dfsCallBack)
in: 0, 0
*** caught segfault ***
address 0x0, cause 'memory not mapped'
Traceback:
1: .Call("R_igraph_dfs", graph, root, neimode, unreachable, as.logical(order), as.logical(order.out), as.logical(father), as.logical(dist), in.callback, out.callback, extra, rho, PACKAGE = "igraph")
2: graph.dfs(g, 1, in.callback = dfsCallBack)
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:
这里有什么问题?此外,igraph 在处理这些错误方面可能应该更加健壮,因为 R 的崩溃对于像 R 这样的高级语言来说并不理想。