title: Inplace modification of S4 object: pro and cons
body: <p>Using <code>eval.parent</code> and <code>substitute</code>, it is possible to write a function that modifies its argument; for example:</p>
  
  <pre><code>&gt; setClass("foo", representation(bar="vector"))
  &gt; f &lt;- function(x) eval.parent(substitute(x@bar &lt;- x@bar+1))
  &gt; a &lt;- new("foo", bar = 0)
  &gt; a
  An object of class "foo"
  Slot "bar":
  [1] 0
  
  &gt; f(a)
  &gt; a
  An object of class "foo"
  Slot "bar":
  [1] 1
  </code></pre>
  
  <p>However most of the time people prefer to write it as follows:</p>
  
  <pre><code>&gt; g &lt;- function(x) { x@bar &lt;- x@bar + 1; x }
  &gt; a &lt;- g(a)
  &gt; a
  An object of class "foo"
  Slot "bar":
  [1] 2
  </code></pre>
  
  <p>Are there any problems with the first method? </p>
  
  <p>Would it be ok to use it in a package submitted to the CRAN (there’s no warning with <code>check --as-cran</code>, so the answer should be yes)?</p>
  
  <p>Thank you for your thoughts.</p>