title: How control output redirection in R via function parameter?
body: <p>I try to redirect cat() output depending on a function parameter as shown below. I am not sure how to avoid an overflow by recursive reference or a stack overflow.</p>
  
  <pre><code>testme1 = function(cat=cat) {
  cat("This is testme1\n")
  }
  
  testme2 = function(cat=function(...){cat(...)}) {
  cat("This is testme2\n")
  }
  
  &gt; testme1()                           # Error in testme1() : 
                                        # promise evaluation     läuft bereits: rekursive Referenz auf das Standardargument oder frühere Fehler?
  &gt; testme1(cat=cat)                    # works
  &gt; testme1(cat=function(...)cat(file="huhu.txt",...)) # works
  
  &gt; testme2()                           # Error: protect(): protection stack overflow
  &gt; testme2(cat=cat)                    # works
  &gt; testme2(cat=function(...)cat(file="huhu.txt",...)) # works
  </code></pre>