dendrapply错误:C堆栈使用率太接近限制
我用dendrapply错误:C堆栈使用率太接近限制,r,apply,dendrogram,R,Apply,Dendrogram,我用R的dendrapply这样: dendrapply(dendro, function(n) utils::str(attributes(n))) 其中,dendro是一个高度为2的树状图,共有2个分支和5902个成员 运行一段时间后,它会因以下错误而崩溃: Error: C stack usage 7971524 is too close to the limit 有什么想法吗?看起来你有一个无限递归的情况,这是因为你的函数中没有返回节点。如果您只是想将每个节点的属性结构打印到控制台
R
的dendrapply
这样:
dendrapply(dendro, function(n) utils::str(attributes(n)))
其中,dendro
是一个高度为2的树状图,共有2个分支和5902个成员
运行一段时间后,它会因以下错误而崩溃:
Error: C stack usage 7971524 is too close to the limit
有什么想法吗?看起来你有一个无限递归的情况,这是因为你的函数中没有返回节点。如果您只是想将每个节点的属性结构打印到控制台,请在函数中返回n
,如下所示:
print_attrs <- function(n){
utils::str(attributes(n))
return(n)
}
dendrapply(dendro, print_attrs)
打印属性
list_attrs <- function(x){
out <- vector(mode = "list", length = attr(x, "members"))
counter <- 1
get_node_attrs <- function(n){
out[[counter]] <<- attributes(n)
counter <<- counter + 1
return(n)
}
tmp <- dendrapply(x, get_node_attrs)
return(out)
}
myattributes <- list_attrs(dendro)