R 的解释:options(expressions=) 给非计算机科学家 [英] Explanation of R: options(expressions=) to non-computer scientists

查看:90
本文介绍了R 的解释:options(expressions=) 给非计算机科学家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个递归函数形式

I have written a recursive function of the form

foo=function(vars,i=2){
  **do something with vars**
  if(i==length(vars)){
    return(**something**)
  }else{
    foo(vars,i+1)
  }
}

length(vars) 大约为 1500.当我执行它时,出现错误

length(vars) is around 1500. When I execute it, I got the error

Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)?

公平,所以我增加了

options(expressions=10000)

然后就可以了.

但是当我阅读 options 的关于 expressions= 的帮助文档时,我只是不明白它在说什么.此外,它建议

But when I read the help doc of options regarding expressions=, i just don't understand what it is saying. Furthermore, it suggests

...如果你增加它,你可能还想用更大的开始R保护栈;...

...If you increase it, you may also want to start R with a larger protection stack;...

那么有人能告诉我发生了什么吗,如果我应该像我一样增加 expressions 参数,以及我是否应该一起修改其他东西.

So can someone tell me what's is going on, if I should have increased the expressions parameters as I have, and if I should modify something else together with it.

推荐答案

在此走捷径... 表达式 -option 设置将被评估的嵌套表达式的最大数量.使用深度递归有时会超出默认值,增加值通常可以解决问题.但如果没有(给出新的错误消息),您可能需要额外增加保护堆栈的大小.计算机将有关活动例程的信息存储在堆栈中.有时,当信息不太适合堆栈时,信息会超出堆栈边界写入,这很糟糕,因为它通常会产生例如内存访问问题.这可以通过在启动 R 时设置选项 --max-ppsize 来纠正.这就像当孩子透支当前纸张时给他或她一张更大的纸张,并为表格着色.

Cutting some corners here... The expressions -option sets the maximum number of nested expressions that will be evaluated. With deep recursion the default is sometimes exceeded, and increasing the value often solves the problem. But if it doesn't (a new error message is given), you might need to additionally increase the size of the protection stack. Computers store information about the active routines in stacks. Sometimes when the information doesn't quite fit to the stack, the information is written beyond the stacks boundary, which is bad, since it typically creates, e.g., memory access problems. This can potentially be rectified by by setting the option --max-ppsize when starting R. It's like giving a child a larger paper when he or she overdraws the current paper, and colors the table too.

有关更多背景信息,请参阅维基百科及其链接.有关 R 命令行选项的详细信息,请参阅 R 简介,第 B.1 节.

For more background, see Wikipedia, and links thereof. For details of R's command line options, see An Introduction to R, section B.1.

这篇关于R 的解释:options(expressions=) 给非计算机科学家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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