我尝试根据函数参数重定向 cat() 输出,如下所示。我不确定如何通过递归引用或堆栈溢出来避免溢出。
testme1 = function(cat=cat) {
cat("This is testme1\n")
}
testme2 = function(cat=function(...){cat(...)}) {
cat("This is testme2\n")
}
> testme1() # Error in testme1() :
# promise evaluation läuft bereits: rekursive Referenz auf das Standardargument oder frühere Fehler?
> testme1(cat=cat) # works
> testme1(cat=function(...)cat(file="huhu.txt",...)) # works
> testme2() # Error: protect(): protection stack overflow
> testme2(cat=cat) # works
> testme2(cat=function(...)cat(file="huhu.txt",...)) # works