dendrapply错误:C堆栈使用率太接近限制 [英] dendrapply Error: C stack usage is too close to the limit

查看:1106
本文介绍了dendrapply错误:C堆栈使用率太接近限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以这种方式使用Rdendrapply:

dendrapply(dendro, function(n) utils::str(attributes(n)))

其中dendro'dendrogram' with 2 branches and 5902 members total, at height 2.

运行一段时间后,由于以下错误而崩溃:

After a while that it's running it crashes with this error:

Error: C stack usage  7971524 is too close to the limit

有什么主意吗?

推荐答案

您似乎遇到了无限递归的情况,这是因为函数中未返回节点.如果您只是想将每个节点的属性结构打印到控制台,请在函数中返回n,如下所示:

It looks like you have an infinite recursion situation which has arisen because the nodes are not returned in your function. If you are just looking to print the structure of the attributes of each node to the console, return n in the function like so:

print_attrs <- function(n){
  utils::str(attributes(n))
  return(n)
}
dendrapply(dendro, print_attrs)

鉴于树状图的大小,似乎最终可能会淹没控制台.为每个节点的属性创建一个平坦的(非嵌套的)列表有点棘手,但是一种方法是使用超级赋值运算符<<-来修改函数内函数的父框架中的变量:

Given the size of your dendrogram it seems like this might end up flooding the console. To create a flat (non-nested) list of the attributes of each node is a little bit trickier, but one approach is to use the superassignment operator <<- to modify variables in the parent frame of a function within a function:

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)

请注意,使用<<-时应注意不要在全局环境中修改变量.请参阅帖子更多信息.

Note that care should be taken when using <<- not to modify variables in the global environment. See this post for more info.

这篇关于dendrapply错误:C堆栈使用率太接近限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆