title: define class methods and class variables in R5 reference class
body: <p>I want to know the correct way to define the class methods and class variable in R5 reference class.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>&gt; # define R5 class XX
  &gt; # member variable: ma
  &gt; # member method: mfa
  &gt; XX &lt;- setRefClass("XX",
  +   fields = list(ma = "character"),
  +   methods = list(
  +     mfa = function() return(paste(ma, "*"))
  +     ))
  &gt; 
  &gt; XX
  Generator object for class "XX":
  
  Class fields:
  
  Name:         ma
  Class: character
  
   Class Methods:  
      "callSuper", "copy", "export", "field", "getClass", "getRefClass", "import", "initFields", 
  "mfa"
  
  
   Reference Superclasses:  
      "envRefClass"
  
  &gt; # create an instance of XX
  &gt; x &lt;- XX$new(ma="ma")
  &gt; 
  &gt; # call member method refering to the member variable.
  &gt; x$mfa()
  [1] "ma *"
  &gt; 
  &gt; # here, I define *class* variable
  &gt; XX$cc &lt;- "cc"
  
  &gt; # contents of XX
  &gt; ls(XX)
  [1] "cc"        "className" "def"       "methods"   "new"      
  
  &gt; # here, I define member method referring to the class var.
  &gt; XX$methods(mfc = function() {
  +   return(XX$cc)
  + })
  
  &gt; # it does work.
  &gt; x$mfc()
  [1] "cc"
  </code></pre>
  
  <p>The <code>XX$cc &lt;- "cc"</code> behaves as if the <code>cc</code> is class variable of XX, but I'm not sure if this is a correct way. <br/>
  For example, XX$def &lt;- "hoge" can break the XX class generator.</p>
  
  <p>So, I want to know if there is a standard way to define class variable and methods.</p>
  
  <p>Thanks in advance. </p>