title: Update value of a slot within an R class method
body: <p>I am using S4 oop to run a soil water balance model in R, and having created an object of class waterBalance I cannot update slots from within a method.  There has to be something simple here that I am not seeing.  My update code is:</p>
  
  <pre><code>setGeneric(name="updateASW",def=function(object,...){standardGeneric("updateASW")})
  
  setMethod(f = "updateASW",
  signature(object = "WaterBalance"),
      function(object, radiationI, rainfallI, maxTI, minTI, laiTI, laiWI, monthI, yearI) {
          object@maxT&lt;-maxTI
          object@minT&lt;-minTI
          object@laiT&lt;-laiTI
          object@laiW&lt;-laiWI
          object@month&lt;-monthI
          object@year&lt;-yearI
          object@radiation&lt;-radiationI
          object@precipitation&lt;-rainfallI
          object@availableSoilWater&lt;-object@availableSoilWater+rainfallI-getInterception(object)-penmanMonteith(object)
          if (object@availableSoilWater&gt;object@ASWMax) {
              object@availableSoilWater&lt;-object@ASWMax
          }
          if (object@availableSoilWater&lt;object@ASWMin) {
              object@availableSoilWater&lt;-object@ASWMin
          }
      })
  </code></pre>
  
  <p>I have tested all the other methods for this class and they are giving correct values with no errors.  This method is the only one that tries to update slot values.</p>
  
  <p>When I create an object of class waterBalance and try to run this update code I get:</p>
  
  <pre><code>&gt; testWB&lt;-makeWB(100,200,50,"loam",0.02,0.02,58,300,25,-2,15)
  &gt; testWB
   ASW =  100 
   ASW Max =  200 
   ASW Min =  50 
   LAI of trees =  3 
   LAI of weeds =  0 
   Soil type =  loam 
   Radiation =   
   Rainfall =   
   Max T =   
   Min T =   
   Latitude =  58 
   Altitude =  300 
   Gs Max for trees =  0.02 
   Gs Max for weeds =  0.02 
   Maximum temp for Ps =  25 
   Minimum temp for Ps =  -2 
   OPtimum temp for Ps =  15
  &gt; updateASW(testWB, 25, 0, 25, 10, 6, 0, 7, 2004)
  &gt; testWB
   ASW =  100 
   ASW Max =  200 
   ASW Min =  50 
   LAI of trees =  3 
   LAI of weeds =  0 
   Soil type =  loam 
   Radiation =   
   Rainfall =   
   Max T =   
   Min T =   
   Latitude =  58 
   Altitude =  300 
   Gs Max for trees =  0.02 
   Gs Max for weeds =  0.02 
   Maximum temp for Ps =  25 
   Minimum temp for Ps =  -2 
   OPtimum temp for Ps =  15
  &gt; 
  </code></pre>
  
  <p>So the slot values in the object instance are unchanged.  Can you please tell me where I am going wrong?</p>
  
  <p>Thanks,<br>
  Euan</p>