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

让人想犯罪 __ 提交于 2019-12-31 03:02:55

问题


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(...)?


回答1:


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

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


来源:https://stackoverflow.com/questions/16789510/error-evaluation-nested-too-deeply-infinite-recursion-optionsexpressions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!