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

[Rd] reference classes, LAZY_DUPLICATE_OK, and external pointers

2014-03-02 Thread Ben Bolker
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 terminology. TL;DR Is there an elegant way to force non-lazy/deep co

[Rd] Reference classes use a lot more memory after serialization/unserialization

2012-09-04 Thread Jan Mueller
Hello All, I posted this earlier on R-help but received no answers. This touches the implementation of reference classes so maybe R-devel is a better place. The memory consumption of reference classes seems to increase dramatically (roughly 10x in the example below) with serialization/unserializ

[Rd] Reference classes: assignments to fields

2011-07-31 Thread John Chambers
In R-devel, a recent change (Rev. 56572) makes assignments to fields in reference classes consistent with assignments to slots in S4 classes, when the field was declared with a class in the call to setRefClass(). The value assigned must come from the declared class for the field, if any, or fr

[Rd] Reference Classes, Generator Object

2011-06-10 Thread soeren . vogel
Hello, I am working with a reference class: Foo <- setRefClass("Bar", fields = list( a = "numeric"), methods = list( baz = function( xa ) a <<- xa ) ) x <- Foo$new() x$baz(2) x$a y <- new("Bar") y$baz(4) y$a But that might be confusing, since new(Foo) does not work and neither does Bar$new()

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

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

2011-06-06 Thread Janko Thyson
Dear list, is there a shortcut-function to check whether a class is a Reference Class or not? There's something like this for S4 classes ('isS4(object)'), but I couldn't find anything regarding Ref Classes. Currently, I'm doing it this way, which is a bit clumsy: A <- setRefClass("A", fields

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

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

2011-05-27 Thread Janko Thyson
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, say "MyRefClassVirtual" (which would have

[Rd] Reference Classes: strange behavior when trying to change class def in the same R session

2011-05-26 Thread Janko Thyson
Dear list, I'm getting some strange behavior with Reference Classes every once in a while and I can't really put my finger on the cause. It'd be great if someone using Reference Classes could check if he/she experiences similar problems: The thing is that when I alter the definition of a Ref

[Rd] Reference Classes: getter and setter functions/methods and possible shortcuts

2011-05-26 Thread Janko Thyson
Hi everyone, just wanted to ask what's the smartest/recommended way of defining getter and setter function *shortcuts* (i.e. something like "[", "[<-") for Reference Class objects? Or is it desired to not use this stuff, but define methods like 'obj$getSubset(row=1:3, col=1)' and 'obj$setSubse

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

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

2011-05-10 Thread 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 Classes now available. Along with the discove

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

[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 Janko Thyson
Sorry guys, but I chose a really stupid name before (no "reference classes"). Hope it's okay to re-post. Cheers, Janko >>> ORIGINAL MESSAGE <<< Dear list, Is it possible to update or reassign '.self' with an image of '.self' (e.g. a locally stored .Rda file) from within a method? I know t

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

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

2011-04-30 Thread Chad Goymer
I've been trying to use methods for reference classes via the notation "[[...]]" (X[["doSomething"]] rather than X$doSomething), but it failed to work. However, I did find that if you use the usual "$" notation first, "[[...]]" can be used afterwards. The following simple example illustrates th

[Rd] Reference classes: error with missing arguments in method calls

2011-02-20 Thread Janko Thyson
Dear list, I'm having problems in understanding an error that pops up in the context of missing arguments with methods of reference class objects. Because of the following statement taken from '?referenceClass', my ref class methods call explicit S4 methods: "Reference methods should be ke

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

[Rd] Reference classes and ".requireCachedGenerics"

2011-02-15 Thread Jon Clayden
Dear all, If I load a package which creates reference classes whilst another such package is also loaded, I get a warning about masking of the ".requireCachedGenerics" variable. (FWIW, both packages are lazy-loaded.) Googling this variable name turned up only one previous discussion, which didn't

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

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

2010-11-24 Thread Janko Thyson
Dear list, I don't know what's the correct term for this in the OOP context, but is it possible to "clone"/copy an instance of a reference class (say 'a') so that I get an *autonomous* second instance 'b'? Autonomous in the sense that changes to 'a' do not affect 'b'. I know that this is somewha

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

2010-11-23 Thread Janko Thyson
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 removed method until I do an explicit re

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

[Rd] reference classes: question on inheritance

2010-11-21 Thread Janko Thyson
Dear list, I have a reference class which should act as a "generic" superclass for other classes. I've read the respective section at ?setRefClass and put the name of the superclass to the 'contains' argument of an example subclass (see class defs below). Classnames are set in a way that shouldn't

[Rd] Reference classes: opinion on OOP design

2010-11-17 Thread Janko Thyson
Dear list, I'm aware that this post does not really comply with the posting guide with respect to "providing a minimal reproducible code example". But I do hope it's okay that I spared uninterested readers by putting that into the attachment ;-) The thing is that I'm not really familiar with "tru

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

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

2010-11-17 Thread Janko Thyson
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 from a database (or some other loca

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

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

2010-10-28 Thread Daniel Lee
Is it possible to override the $new(...) in the reference class generator? I have tried adding a "new" method to the methods of the class, but that is obviously not correct. I have also tried adding it to the class generator, but the class generator still uses the default constructor. As a si

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

[Rd] Reference classes

2010-10-22 Thread Jon Clayden
Dear all, First, many thanks to John Chambers, and anyone else who was involved, for the new support for "reference classes" in R 2.12.0. It's nice to see this kind of functionality appear in a relatively R-like form, and with the blessing of the core team. In some contexts it is undoubtedly appea