【发布时间】:2013-05-28 10:17:02
【问题描述】:
我已经定义了max()函数如下:
max <- function(...) max(...,na.rm=T)
但它无法计算 max(1:5) 并出现以下错误:Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
查看traceback() 中的结果可以识别问题:
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
新的max(...) 函数在主体中调用自身,而不是原来的max() 函数。一个简单的解决方案是重命名函数:Max <- function(...) max(...,na.rm=T)。是否有其他不错的选择而不重命名 -i.e.强制 R 在新 max(...) 的主体中运行原始 max() 函数?
【问题讨论】: