<br><br><div class="gmail_quote">On Mon, Nov 1, 2010 at 3:28 PM, Douglas Bates <span dir="ltr"><<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a>></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'm confused about accessor functions as described in<br>
help("setRefClass") under the argument "fields". 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 <- setRefClass("Myclass",<br>
fields = list(extptr = externalptr,<br> xyz = function(arg=nil) {<br> .Call('accessorXyz',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 <- Module('Myclass',PACKAGE='YourPackage')$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'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'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>
<<a href="mailto:romain@r-enthusiasts.com">romain@r-enthusiasts.com</a>> wrote:<br>
> Le 01/11/10 16:34, Douglas Bates a écrit :<br>
>><br>
>> On Mon, Nov 1, 2010 at 10:26 AM, Douglas Bates<<a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a>><br>
>> wrote:<br>
>>><br>
>>> What is a good place to start reading about using the newly installed<br>
>>> reference classes in R to interface with Rcpp?<br>
>><br>
>> To answer my own question, the "Rcpp Modules" vignette.<br>
><br>
> Perhaps it will be once we update the vignette. The content dates from<br>
> before we used reference classes.<br>
><br>
> For reference classes themselves, the best place to look is<br>
> ?ReferenceClasses<br>
><br>
> As Dirk pointed out, my chicago slides or our google slides might give<br>
> nuggets of information.<br>
><br>
> I guess it also depends what specifically you want to learn about them.<br>
> Exposing a class is essentially the same as before reference classes.<br>
><br>
> Deriving a C++ class, adding R methods to a class, etc ... is a new feature<br>
> we get for free with reference classes. This is not really Rcpp specific, so<br>
> maybe ?ReferenceClasses gives enough hints.<br>
><br>
> Romain<br>
><br>
> --<br>
> Romain Francois<br>
> Professional R Enthusiast<br>
> +33(0) 6 28 91 30 30<br>
> <a href="http://romainfrancois.blog.free.fr" target="_blank">http://romainfrancois.blog.free.fr</a><br>
> |- <a href="http://bit.ly/czHPM7" target="_blank">http://bit.ly/czHPM7</a> : Rcpp Google tech talk on youtube<br>
> |- <a href="http://bit.ly/9P0eF9" target="_blank">http://bit.ly/9P0eF9</a> : Google slides<br>
> `- <a href="http://bit.ly/cVPjPe" target="_blank">http://bit.ly/cVPjPe</a> : Chicago R Meetup slides<br>
><br>
><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>
><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>