<br><br><div class="gmail_quote">On Mon, Nov 1, 2010 at 3:28 PM, Douglas Bates <span dir="ltr">&lt;<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I should probably ask this question on R-devel as it is not directly<br>
an Rcpp question but the thread started here so ...<br>
<br>
I&#39;m confused about accessor functions as described in<br>
help(&quot;setRefClass&quot;) under the argument &quot;fields&quot;.  It states<br>
<br>
          The element in the list can alternatively be an _accessor<br>
          function_, a function of one argument that returns the field<br>
          if called with no argument or sets it to the value of the<br>
          argument otherwise. Accessor functions are used internally<br>
          ...<br></blockquote><div><br>The last example I sent was for accessor functions (auto-generation<br>of getX() and setX()). To use accessor fields you can do something<br>like:<br><br>clgen &lt;- setRefClass(&quot;Myclass&quot;,<br>
    fields = list(extptr = externalptr,<br>      xyz = function(arg=nil) {<br>          .Call(&#39;accessorXyz&#39;,extptr, arg)<br>      })<br><br>Here extptr will have to be set in an initialize method, and<br>the .Call will return xyz (a field in the C++ structure<br>
pointed to by extptr) when arg is nil, otherwise the<br>supplied arg will be assigned to this field.<br><br>Romain has partially wrapped this process in Module,<br>where you can get a similar effect with:<br><br>clgen &lt;- Module(&#39;Myclass&#39;,PACKAGE=&#39;YourPackage&#39;)$Myclass<br>
<br>The times they are a-changin...<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
The application I have in mind is classes of objects representing the<br>
response and auxiliary information in linear, generalized linear,<br>
nonlinear, and generalized nonlinear models.  An S4 implementation is<br>
in the MatrixModels package but the syntax of the update methods is<br>
awkward because they must replace slots then return the whole object,<br>
which can be rather large.  What I would like to do is have an update<br>
method that takes a new value of the linear predictor, updates the<br>
mean, the residuals, possibly the weights (for GLMs) and the weighted<br>
residuals.  After the update, methods for other objects can query the<br>
values of the weighted residuals, square root of the residual weights,<br>
square root of the X weights, etc.<br>
<br>
I&#39;m trying to decide if the fields that can be queried should be<br>
declared as fields or as accessor functions.<br>
<br>
I haven&#39;t discovered any examples that declare accessor functions in<br>
the fields section.  Can anyone point out such an example to me?<br>
<div><div></div><div class="h5"><br>
On Mon, Nov 1, 2010 at 10:44 AM, Romain Francois<br>
&lt;<a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a>&gt; wrote:<br>
&gt; Le 01/11/10 16:34, Douglas Bates a écrit :<br>
&gt;&gt;<br>
&gt;&gt; On Mon, Nov 1, 2010 at 10:26 AM, Douglas Bates&lt;<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a>&gt;<br>
&gt;&gt;  wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; What is a good place to start reading about using the newly installed<br>
&gt;&gt;&gt; reference classes in R to interface with Rcpp?<br>
&gt;&gt;<br>
&gt;&gt; To answer my own question, the &quot;Rcpp Modules&quot; vignette.<br>
&gt;<br>
&gt; Perhaps it will be once we update the vignette. The content dates from<br>
&gt; before we used reference classes.<br>
&gt;<br>
&gt; For reference classes themselves, the best place to look is<br>
&gt; ?ReferenceClasses<br>
&gt;<br>
&gt; As Dirk pointed out, my chicago slides or our google slides might give<br>
&gt; nuggets of information.<br>
&gt;<br>
&gt; I guess it also depends what specifically you want to learn about them.<br>
&gt; Exposing a class is essentially the same as before reference classes.<br>
&gt;<br>
&gt; Deriving a C++ class, adding R methods to a class, etc ... is a new feature<br>
&gt; we get for free with reference classes. This is not really Rcpp specific, so<br>
&gt; maybe ?ReferenceClasses gives enough hints.<br>
&gt;<br>
&gt; Romain<br>
&gt;<br>
&gt; --<br>
&gt; Romain Francois<br>
&gt; Professional R Enthusiast<br>
&gt; +33(0) 6 28 91 30 30<br>
&gt; <a href="http://romainfrancois.blog.free.fr" target="_blank">http://romainfrancois.blog.free.fr</a><br>
&gt; |- <a href="http://bit.ly/czHPM7" target="_blank">http://bit.ly/czHPM7</a> : Rcpp Google tech talk on youtube<br>
&gt; |- <a href="http://bit.ly/9P0eF9" target="_blank">http://bit.ly/9P0eF9</a> : Google slides<br>
&gt; `- <a href="http://bit.ly/cVPjPe" target="_blank">http://bit.ly/cVPjPe</a> : Chicago R Meetup slides<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Rcpp-devel mailing list<br>
&gt; <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
&gt; <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
&gt;<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br>