错误:评估嵌套太深:无限递归/选项(表达式=)? [英] Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

查看:891
本文介绍了错误:评估嵌套太深:无限递归/选项(表达式=)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了 max()函数如下:

  max < -  function(...)max(...,na.rm = T)

但它无法计算 max(1:5),并出现以下错误:错误:评估嵌套过深:无限递归/选项(表达式=) ?



观察结果 traceback()可以确定问题:

  88:max(...,na.rm = T)在PositionMeth.R#1521 
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
pre>

新的 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 original max() 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 original max() function in the body of the new max(...)?

解决方案

You want to call the original max function using its namespace, base:

max <- function(...) base::max(...,na.rm=T)

这篇关于错误:评估嵌套太深:无限递归/选项(表达式=)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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