错误:评估嵌套太深:无限递归/选项(表达式=)? [英] Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
问题描述
我定义了 max()
函数如下:
max < - function(...)max(...,na.rm = T)
但它无法计算 max(1:5)
,并出现以下错误:错误:评估嵌套过深:无限递归/选项(表达式=) ?
观察结果 traceback()
可以确定问题:
88:max(...,na.rm = T)在PositionMeth.R#1521
pre>
87:max(。 ..,na.rm = T)在PositionMeth.R#1521
86:max(...,na.rm = T)在PositionMeth.R#1521
85:max(... ,位置计数器上的na.rm = T)#1521
84:位置计数器上的最大值(...,na.rm = T)#1521
新的
max(...)
函数在主体中调用自身,而不是原始的max()
函数。一个简单的解决方案是重命名函数:Max < - function(...)max(...,na.rm = T)
。有没有其他不错的选择,即重命名 - 即。强制R运行新的max(...)
?中的原始max()
p>
解决方案您想使用其名称空间
base
调用原始的max函数:
max < - function(...)base :: max(...,na.rm = T)
I have defined
max()
function as below:max <- function(...) max(...,na.rm=T)
But it fails to compute
max(1:5)
with following error:Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Watching the result in
traceback()
identifies the problem:88: max(..., na.rm = T) at PositionMeth.R#1521 87: max(..., na.rm = T) at PositionMeth.R#1521 86: max(..., na.rm = T) at PositionMeth.R#1521 85: max(..., na.rm = T) at PositionMeth.R#1521 84: max(..., na.rm = T) at PositionMeth.R#1521
The new
max(...)
function is calling itself in the body, not the originalmax()
function. A simple solution is to rename the function:Max <- function(...) max(...,na.rm=T)
. Is there other good options without renaming -i.e. forcing R to run originalmax()
function in the body of the newmax(...)
?解决方案You want to call the original max function using its namespace,
base
:max <- function(...) base::max(...,na.rm=T)
这篇关于错误:评估嵌套太深:无限递归/选项(表达式=)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文