问题
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