如何在 R 中读取回溯

How to read a traceback in R

我有一个很大的多边形数据集,并且通过一个循环,我在某个时候尝试查找、计算和存储交点。在第 870 次迭代时,循环停止并且出现错误:

Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false,  : 
  TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point 26.437120350000001 39.241770119999998 at 26.437120350000001 39.241770119999998

我用的是traceback(),但我其实看不懂:

4: .Call("rgeos_intersection", .RGEOS_HANDLE, spgeom1, spgeom2, 
       byid, ids, PACKAGE = "rgeos")
3: RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false, 
       "rgeos_intersection")
2: gIntersection(combinations[[i]][[1, m]], combinations[[i]][[2, 
       m]]) at #17 . Can anyone explain what to look in ` traceback`?

谁能告诉我在 traceback 中要看什么?

谢谢

它从字面上向您展示了调用函数的方式以及发生错误的位置。检查这个例子:

a <- function(x) {
  b <- function(y) {
    c <- function(z) {
     stop('there was a problem')  
    }
    c()
  }
  b()
}

当我调用 a():

> a()

Error in c() : there was a problem 
4. stop("there was a problem") 
3. c() 
2. b() 
1. a() 

在上面的示例中,您可以看到 a 调用了 b,后者又调用了 c,然后在 c 中发生了错误。它向您展示了调用环境。