r - 如何在 R 中读取回溯

标签 r function loops traceback

我有一个大的多边形数据集,并且通过循环,我尝试在某个时刻查找、计算和存储交集。在第 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,而 b 又调用了 c,然后在 c 中发生了错误。它向您显示调用环境。

关于r - 如何在 R 中读取回溯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47414119/

相关文章:

java - Java 数组示例

r - R 和 C 堆栈使用中允许的内存

mysql - Apache 日志文件中的奇怪引荐来源网址 : empty string and what looks like MySQL code

r - 将脚本与 .GlobalEnv : Source script that source scripts 分开

c - 使用指向从函数返回的结构的指针

python - 从列表中获取匹配的字符串并创建新列表

r - 在bookdown首页之前插入pdf

c++ - 从可变参数函数将函数应用于参数包的所有元素

r - 提取具有缺失值阈值的变量名称

JAVA:比较字符串和子字符串