Re: [Rd] reference classes, LAZY_DUPLICATE_OK, and external pointers

2014-03-02 Thread Ben Bolker
On 14-03-02 08:05 PM, Simon Urbanek wrote: > Ben, > > On Mar 2, 2014, at 7:38 PM, Ben Bolker wrote: > >> We (the lme4 authors) are having a problem with doing a proper >> deep copy of a reference class object in recent versions of R-devel >> with the LAZY_DUPLICATE_OK flag in src/main/bind.c ena

Re: [Rd] reference classes, LAZY_DUPLICATE_OK, and external pointers

2014-03-02 Thread Simon Urbanek
Ben, On Mar 2, 2014, at 7:38 PM, Ben Bolker wrote: > We (the lme4 authors) are having a problem with doing a proper deep > copy of a reference class object in recent versions of R-devel with > the LAZY_DUPLICATE_OK flag in src/main/bind.c enabled. > > Apologies in advance for any improper termi

Re: [Rd] Reference Classes: shortcut like 'isS4' for Ref Classes?

2011-06-07 Thread Janko Thyson
Thanks for the answer! Sorry, must have missed that part of the help page. Your second approach is exactly what I was looking for. Regards, Janko On 06.06.2011 23:38, John Chambers wrote: As it says on the help page ?ReferenceClasses: All reference classes inherit from the class "envRefClass"

Re: [Rd] Reference Classes: shortcut like 'isS4' for Ref Classes?

2011-06-06 Thread John Chambers
As it says on the help page ?ReferenceClasses: All reference classes inherit from the class "envRefClass" So, is(x, "envRefClass") And, less well documented but less typing: is(x, "refClass") also works. On 6/6/11 9:48 AM, Janko Thyson wrote: Dear list, is there a shortcut-function to c

Re: [Rd] Reference Classes/S4 Classes: can method dispatch check superclasses BEFORE resorting to method for "ANY"?

2011-05-27 Thread Janko Thyson
Cool, thanks a lot for the insight! I forgot that there is the option to use 'contains="VIRTUAL" and probably out of laziness usually set my virtual S4 classes simply via 'setClass("Something")'. On 27.05.2011 15:22, Martin Morgan wrote: > On 05/27/2011 06:13 AM, Janko Thyson wrote: >> Dear list

Re: [Rd] Reference Classes/S4 Classes: can method dispatch check superclasses BEFORE resorting to method for "ANY"?

2011-05-27 Thread Martin Morgan
On 05/27/2011 06:13 AM, Janko Thyson wrote: Dear list, is it possible that method dispatch checks for superclasses/virtual classes before checking "ANY"? I'd like to build a generic initialization method for all my Reference Class (say "MyDataFrame") objects by having them inherit from class, s

Re: [Rd] Reference Classes copy(shallow=FALSE) unexpected behavior.

2011-05-11 Thread Manuel Castejón Limas
Dear Hadley, Thank you very much for your interest in the question proposed. The Con class is a Reference Class. P and k are from class listCon. I provide in the following lines a little more detail in order to be able to reproduce the case. #Class declaration gCon <- setRefClass("Con", fields=l

Re: [Rd] Reference Classes copy(shallow=FALSE) unexpected behavior.

2011-05-11 Thread Manuel Castejón Limas
Dear Hadley and John, My main interest in the question was to understand what was happening. Thank you very much for your clarifications and the piece of code. Manuel El 11/05/11 18:32, "John Chambers" escribió: >Good suggestion for this case. > >But the general problem is tricky. What abou

Re: [Rd] Reference Classes copy(shallow=FALSE) unexpected behavior.

2011-05-11 Thread Hadley Wickham
> But the general problem is tricky.  What about reference objects contained > in attributes or slots of other objects, etc?  What is  needed for total > copying is a switch in the low-level duplication code that says to copy > reference objects.  It's also possible that one does NOT want all such

Re: [Rd] Reference Classes copy(shallow=FALSE) unexpected behavior.

2011-05-11 Thread John Chambers
Good suggestion for this case. But the general problem is tricky. What about reference objects contained in attributes or slots of other objects, etc? What is needed for total copying is a switch in the low-level duplication code that says to copy reference objects. It's also possible that

Re: [Rd] Reference Classes copy(shallow=FALSE) unexpected behavior.

2011-05-11 Thread Hadley Wickham
Hi Manuel, The source code for copy is short and pretty readable, so I'd encourage you to look at it: > setRefClass("XXX")$copy Class method definition for method copy() function (shallow = FALSE) { def <- .refClassDef value <- new(def) vEnv <- as.environment(value) selfEnv <- as.

Re: [Rd] Reference Classes copy(shallow=FALSE) unexpected behavior.

2011-05-11 Thread Hadley Wickham
2011/5/10 Manuel Castejón Limas : > Dear all, > > I've just discovered the 'Reference Classes'. > In a previous attempt ---a year ago--- to re-implement in a Object Oriented > fashion the AMORE package using S4 classes I strongly felt the need of such > capability. It's great to have the Reference

Re: [Rd] Reference Classes: replacing '.self' with an .Rda image of '.self' from within a method? (was replacing '.self' with an .Rda image of '.self' from within a method?)

2011-05-04 Thread John Chambers
It makes no sense to replace the .self field: that field is initialized to be a reference to the object. If you change it, it's no longer that reference. There are many things wrong with your example, so it's better to take a very simple version: > mkTest <- setRefClass("test",fields = lis

Re: [Rd] Reference Classes: (Was: Accessing methods via [[...]], bug?)

2011-05-04 Thread Hadley Wickham
On Wed, May 4, 2011 at 11:35 AM, John Chambers wrote: > On 5/4/11 9:24 AM, Hadley Wickham wrote: Are you familiar with "Concepts, Techniques, and Models of Computer Programming" by van Roy and Haridi?  That's what really helped me to understand the strengths and weaknesses of t

Re: [Rd] Reference Classes: (Was: Accessing methods via [[...]], bug?)

2011-05-04 Thread John Chambers
On 5/4/11 9:24 AM, Hadley Wickham wrote: Are you familiar with "Concepts, Techniques, and Models of Computer Programming" by van Roy and Haridi? That's what really helped me to understand the strengths and weaknesses of the various styles of programming. Thanks, I wasn't. Yes, interesting sim

Re: [Rd] Reference Classes: Accessing methods via [[...]], bug?

2011-05-04 Thread Hadley Wickham
>> Are you familiar with "Concepts, Techniques, and Models of Computer >> Programming" by van Roy and Haridi?  That's what really helped me to >> understand the strengths and weaknesses of the various styles of >> programming. > > Thanks, I wasn't.  Yes, interesting similar distinction between func

Re: [Rd] Reference Classes: Accessing methods via [[...]], bug?

2011-05-04 Thread John Chambers
On 5/3/11 2:39 PM, Hadley Wickham wrote: Part of the motivation for the reference classes was to bring a general OOP view to R. One can start from some essential concepts of objects and their properties, inheritance and class definition, as have evolved over a very long time. Next, there is a f

Re: [Rd] Reference Classes: Accessing methods via [[...]], bug?

2011-05-03 Thread Hadley Wickham
> Part of the motivation for the reference classes was to bring a general OOP > view to R.  One can start from some essential concepts of objects and their > properties, inheritance and class definition, as have evolved over a very > long time. > > Next, there is a fundamental choice of paradigm be

Re: [Rd] Reference Classes: Accessing methods via [[...]], bug?

2011-05-03 Thread Geoff Jentry
On Sun, 1 May 2011, Martin Morgan wrote: On 05/01/2011 03:09 PM, John Chambers wrote: It would be interesting to get some experience and opinions on whether this is a good idea or not. It breaks encapsulation, in that the behavior of the class can no longer be inferred from the class definition

Re: [Rd] Reference Classes: Accessing methods via [[...]], bug?

2011-05-01 Thread John Chambers
On 5/1/11 3:37 PM, Martin Morgan wrote: On 05/01/2011 03:09 PM, John Chambers wrote: Yes, as presented on that site it makes a little more sense: "While experimenting with the new reference classes in R I noticed some odd behaviour if you use the "[[ ]]" notation for methods (X[["doSomething"]]

Re: [Rd] Reference Classes: Accessing methods via [[...]], bug?

2011-05-01 Thread Martin Morgan
On 05/01/2011 03:09 PM, John Chambers wrote: Yes, as presented on that site it makes a little more sense: "While experimenting with the new reference classes in R I noticed some odd behaviour if you use the "[[ ]]" notation for methods (X[["doSomething"]] instead of X$doSomething). This notation

Re: [Rd] Reference Classes: Accessing methods via [[...]], bug?

2011-05-01 Thread John Chambers
Yes, as presented on that site it makes a little more sense: "While experimenting with the new reference classes in R I noticed some odd behaviour if you use the "[[ ]]" notation for methods (X[["doSomething"]] instead of X$doSomething). This notation works for fields, but I initially thought

Re: [Rd] Reference Classes: Accessing methods via [[...]], bug?

2011-04-30 Thread Hadley Wickham
If this message is garbled for anyone else, the original question on stackoverflow is here: http://stackoverflow.com/questions/5841339/using-notation-for-reference-class-methods Hadley On Sat, Apr 30, 2011 at 11:35 AM, Chad Goymer wrote: > > I've been trying to use methods for reference classes

Re: [Rd] Reference classes and ".requireCachedGenerics"

2011-02-15 Thread John Chambers
PS: this is another glitch that arises when you don't use NAMESPACE files. If the .requireCachedGenerics is in a NAMESPACE and not exported, the conflict does not arise. On 2/15/11 12:52 PM, John Chambers wrote: No worries, and we will get rid of the warning message. Certain of the S4 classe

Re: [Rd] Reference classes and ".requireCachedGenerics"

2011-02-15 Thread John Chambers
No worries, and we will get rid of the warning message. Certain of the S4 classes require methods for particular primitive functions. If a subclass of one of those classes is loaded from a package, then we need to turn on method dispatch for the corresponding primitive(s). For efficiency, th

Re: [Rd] Reference Classes: removing methods -> implications for objects/instances of that class

2010-11-27 Thread Vitalie S.
"Janko Thyson" writes: > Dear list, > > just to make sure that I understand 'unregistering' methods for S4 reference > classes correctly: > > If I registered a method and want to 'unregister' (i.e. remove) this method > again, objects/instance created of the respective class still feature the > r

Re: [Rd] Reference Classes: how to clone/copy instances?

2010-11-25 Thread John Chambers
No reference class method explicitly does this, but it's a natural utility. Some form of $copy() will be added. It needs a shallow/deep option; i.e., if a field is itself a reference class object, should that field be cloned as well. The full reflectance available should make a single method

Re: [Rd] reference classes: question on inheritance

2010-11-22 Thread Janko Thyson
> -Ursprüngliche Nachricht- > Von: r-devel-boun...@r-project.org [mailto:r-devel-boun...@r- > project.org] Im Auftrag von John Chambers > Gesendet: Montag, 22. November 2010 18:51 > An: r-devel@r-project.org > Betreff: Re: [Rd] reference classes: quest

Re: [Rd] reference classes: question on inheritance

2010-11-22 Thread John Chambers
>> >> What am I doing wrong here? Not using a recent enough version of R probably (and not telling us what version you are using). The warning (not an error) should not appear in current r-devel or 2.12-patched. In other words, works fine for me. John On 11/21/10 3:40 PM, Janko Thyson wrot

Re: [Rd] reference classes: question on inheritance

2010-11-21 Thread Janko Thyson
Hmm, interesting: it's the virtual class that causes the trouble. If a virtual class is a ref class, everything works fine. If it's a standard S4 class, it results in the error below. Regards, Janko > -Ursprüngliche Nachricht- > Von: Janko Thyson [mailto:janko.thy...@ku-eichstaett.de] > G

Re: [Rd] Reference classes: accessor functions via 'getRefClass(...)$accessors(...)'

2010-11-17 Thread Janko Thyson
Thanks a lot for the comments! I'll give the serveral alternatives a try to see if it gets me what I want. Cheers, Janko > -Ursprüngliche Nachricht- > Von: Vitalie S. [mailto:spinuvit.l...@gmail.com] > Gesendet: Mittwoch, 17. November 2010 13:51 > An: Janko Thyson > Cc: 'r-de...@r-projec

Re: [Rd] Reference classes: accessor functions via 'getRefClass(...)$accessors(...)'

2010-11-17 Thread Vitalie S.
"Janko Thyson" writes: > Hi there, > > I'd like to choose between an "static" and "dynamic" access of a reference > class field, say 'a'. > > myObj <- getRefClass("Blabla")$new() > > Static: myObj$a > > Dynamic: myObj$a.get() where the function retrieves the data > f

Re: [Rd] Reference classes: accessor functions via 'getRefClass(...)$accessors(...)'

2010-11-17 Thread Romain Francois
Le 17/11/10 13:07, Janko Thyson a écrit : Hi there, I'd like to choose between an "static" and "dynamic" access of a reference class field, say 'a'. myObj<- getRefClass("Blabla")$new() Static: myObj$a Dynamic: myObj$a.get() where the function retrieves the

Re: [Rd] Reference Classes: Generalizing Reference Class Generator objects?

2010-10-29 Thread Vitalie S.
John Chambers writes: > Good diagnoses. > > This thread brought up a point or two that needed some fixes to the > documentation and code. They should be in > r-devel and 2.12 patched (from rev. 53471). > > Briefly: > > - Initialization methods should take account of future subclasses to your >

Re: [Rd] Reference Classes: Generalizing Reference Class Generator objects?

2010-10-29 Thread John Chambers
Good diagnoses. This thread brought up a point or two that needed some fixes to the documentation and code. They should be in r-devel and 2.12 patched (from rev. 53471). Briefly: - Initialization methods should take account of future subclasses to your class by including and passing on the

Re: [Rd] Reference Classes: Generalizing Reference Class Generator objects?

2010-10-28 Thread Jon Clayden
?ReferenceClasses says "Reference methods can not themselves be generic functions; if you want additional function-based method dispatch, write a separate generic function and call that from the method". So I think you'd need to take that approach in your "initialize" method. Hope this helps, Jon

Re: [Rd] Reference Classes: Generalizing Reference Class Generator objects?

2010-10-28 Thread Daniel Lee
Thank you. Your example really clarifies what the $initialize(...) function is supposed to do. Do you know if there is a straightforward way to dispatch the $new(...) method based on the signature of the arguments? I am thinking along the lines of S4 methods with valid signatures. Thanks aga

Re: [Rd] Reference Classes: Generalizing Reference Class Generator objects?

2010-10-28 Thread Jon Clayden
Sorry - you don't need to assign the value of initFields(). I was going to do it in two lines but then realised one was enough... :) TestClass <- setRefClass ("TestClass", fields = list (text = "character"), methods = list ( initialize = function (text) { initFields(te

Re: [Rd] Reference Classes: Generalizing Reference Class Generator objects?

2010-10-28 Thread Jon Clayden
Hi Daniel, I think you want to define an "initialize" method, as in TestClass <- setRefClass ("TestClass", fields = list (text = "character"), methods = list ( initialize = function (text) { object <- initFields(text=paste(text,"\n")) }, print = functio

Re: [Rd] Reference classes

2010-10-26 Thread John Chambers
What you've written will certainly generate an infinite recursion. How could it not? Specifying an accessor function says to the system "Any reference to this field should be evaluated by calling this function." But then you refer to the field in the function itself, which will result in a c

Re: [Rd] Reference classes

2010-10-26 Thread Jon Clayden
On 23 October 2010 00:52, Jon Clayden wrote: > On 22 October 2010 18:55, John Chambers wrote: > >>> As a suggestion, it would be nice if the accessors() method could be >>> used to create just "getters" or just "setters" for particular fields, >>> although I realise this can be worked around by r

Re: [Rd] Reference classes

2010-10-22 Thread Jon Clayden
On 22 October 2010 18:55, John Chambers wrote: >> As a suggestion, it would be nice if the accessors() method could be >> used to create just "getters" or just "setters" for particular fields, >> although I realise this can be worked around by removing the unwanted >> methods afterwards. > > In o

Re: [Rd] Reference classes

2010-10-22 Thread John Chambers
One correction: On 10/22/10 10:55 AM, John Chambers wrote: . As a suggestion, it would be nice if the accessors() method could be used to create just "getters" or just "setters" for particular fields, although I realise this can be worked around by removing the unwanted methods afterwards.

Re: [Rd] Reference classes

2010-10-22 Thread John Chambers
Last question first: > > More generally, I was wondering how firm the commitment is to > providing this kind of programming mechanism. I know it's likely to > change in some ways in future releases, but can I use it in packages, > trusting that only a few tweaks will be needed for compatibility w