title: Non-standard set-functions in R Reference Classes
body: <p>Is it possible to get the syntax</p>
  
  <pre><code>foo$bar(x) &lt;- value
  </code></pre>
  
  <p>to work where <code>foo</code> is a reference class object and <code>bar</code> is a method?
  I.e. is it possible to do "subset assigment" and have "replacement functions" as methods in Reference Classes?</p>
  
  <p>Is the syntax possible to get with other OO systems?</p>
  
  <p><strong>Example:</strong>
  I'll illustrate with a made-up use case. Imagine a reference class, <code>Person</code>, which contains some basic information of a person. Particularly, one field called <code>fullname</code> is a named <code>list</code>:</p>
  
  <pre><code>PersonRCGen &lt;- setRefClass("Person",
                             fields = list(
                               fullname = "list",
                               gender = "character"
                             ))
  </code></pre>
  
  <p>Next, we should define some methods to get and set particular names within the <code>fullnames</code> list which (try) to give the above syntax/interface. My best attempt has so far been:</p>
  
  <pre><code>PersonRCGen$methods(
    name = function(x) { # x is the dataset,
      .self$fullname[[x]]
    },
    `name&lt;-` = function(x, value) {
      .self$fullname[[x]] &lt;- value
    }
  )
  </code></pre>
  
  <p>The naming here should also illustrate what I'm trying to do.</p>
  
  <p>We initialize a new object:</p>
  
  <pre><code>a_person &lt;- PersonRCGen$new(fullname = list(first = "Jane", last = "Doe"),
                              gender = "F")
  </code></pre>
  
  <p>Accessing the <code>fullname</code> field directly and accessing the first and last name by the defined get-function works as intended:</p>
  
  <pre><code>a_person$fullname
  #$`first`
  #[1] "Jane"
  # 
  #$last
  #[1] "Doe"
  
  a_person$name("first")
  #[1] "Jane"
  
  a_person$name("last")
  #[1] "Doe"
  </code></pre>
  
  <p>However, for setting a particular name in the <code>fullname</code> list, I'd like to have the following syntax/interface which unfortuantely fails.</p>
  
  <pre><code>a_person$name("first") &lt;- "Jessie"
  #Error in a_person$name("first") &lt;- "Jessie" : 
  #  target of assignment expands to non-language object
  </code></pre>
  
  <p>I know the following works (which basically renders the method poorly named). </p>
  
  <pre><code>a_person$`name&lt;-`("first", "Johnny")
  a_person$fullname
  #$`first`
  #[1] "Johnny"
  #
  #$last
  #[1] "Doe"
  </code></pre>
  
  <p>In my real use case, I'd like to avoid 'traditional' <code>getName(x)</code> and <code>setName(x, value)</code> names for the get and set functions. </p>