title: R define a function attribute inside the function
body: <p>Is it possible to R define a function attribute inside the very function?<br>
  It can be defined outside, but is there a notation for self-reference inside a function?</p>
  
  <pre><code>f2 = function(x) {
     x/2
     attr(thisObject(),'type')='half' #something like thisObject()
  }
  </code></pre>
  
  <p>It is easy to do this outside the function:  </p>
  
  <pre><code>attr(f2,'type')='half'
  </code></pre>
  
  <p>In a situation, I need to know what kind of function is passed by:  </p>
  
  <pre><code>fCalc=function(f=f2,x){
    if(attr(f,'type')=='half') {
      cat('ok\n')
      return(f(x))
    } else cat( 'not ok')
  }
  fCalc(f2,4)
  ok
  [1] 2
  </code></pre>