Re: [R] How to change the value of a class slot

2005-06-09 Thread Ross Boylan
On Wed, 2005-06-08 at 14:15 +0200, Thomas Petzoldt wrote: ... Hello Ross, I see that your question was related to S4, but I just noticed a solution based on the R.oo package so I thought I would add a solution based on the proto package too. We had similar problems several times ago and (to

Re: [R] How to change the value of a class slot

2005-06-09 Thread Ross Boylan
On Wed, 2005-06-08 at 09:13 +0200, Uwe Ligges wrote: [extensive deletions. Discussion concerned my desire to have a function change the value of an object in a way that had effects outside of the function, without returning the object.] You have to think about scoping rules and it will be

Re: [R] How to change the value of a class slot

2005-06-09 Thread Thomas Petzoldt
Ross Boylan wrote: I believe your example assumes that foo is updating the outer a by cheating and directly modifying enclosing environments. (I figure it also needs to get the name of its actual argument to do this, which would also involve slightly dirty tricks.) This does seem to be the

Re: [R] How to change the value of a class slot

2005-06-09 Thread Duncan Murdoch
On 6/9/2005 3:04 PM, Ross Boylan wrote: On Wed, 2005-06-08 at 09:13 +0200, Uwe Ligges wrote: [extensive deletions. Discussion concerned my desire to have a function change the value of an object in a way that had effects outside of the function, without returning the object.] You have to

Re: [R] How to change the value of a class slot

2005-06-09 Thread Thomas Petzoldt
Ross Boylan wrote: The paper also notes that call-by-value vs call-by-reference, which is the root of the slot update problem, is really orthogonal to the FOOP/COOP distinction. It's easy to imagine FOOP with call-by-reference. R.oo uses references. Yes, it can be found on

Re: [R] How to change the value of a class slot

2005-06-08 Thread Uwe Ligges
Ross Boylan wrote: On Tue, 2005-06-07 at 08:36 +0200, Uwe Ligges wrote: Ross Boylan wrote: On Sat, Jun 04, 2005 at 07:08:56PM +0200, Martin Maechler wrote: Ross nextPath - function(pm){ #pm is a CompletePathMaker Ross[EMAIL PROTECTED] - [EMAIL PROTECTED](1) Ross [etc] If your

Re: [R] How to change the value of a class slot

2005-06-08 Thread Thomas Petzoldt
Ross Boylan wrote: I defined an S4 class with a slot i. Then I wrote a regular function that attempted to increment i. [... details deleted ...] What do I need to do to update slot values? Here are some possibly relevant code fragments setClass(CompletePathMaker,

Re: [R] How to change the value of a class slot

2005-06-07 Thread Uwe Ligges
Ross Boylan wrote: On Sat, Jun 04, 2005 at 07:08:56PM +0200, Martin Maechler wrote: Ross nextPath - function(pm){ #pm is a CompletePathMaker Ross[EMAIL PROTECTED] - [EMAIL PROTECTED](1) Ross [etc] If your nextPath function has 'pm' as its last statement it will return the

RE: [R] How to change the value of a class slot

2005-06-07 Thread Ross Boylan
On Mon, 2005-06-06 at 14:15 -0700, Berton Gunter wrote: I'm puzzled: It looks as if instances of class objects are best thought of as immutable once created. what then is setReplaceMethod() for? assignment operators do the whole object replacement behind the scenes, at least

Re: [R] How to change the value of a class slot

2005-06-07 Thread Ross Boylan
On Tue, 2005-06-07 at 08:36 +0200, Uwe Ligges wrote: Ross Boylan wrote: On Sat, Jun 04, 2005 at 07:08:56PM +0200, Martin Maechler wrote: Ross nextPath - function(pm){ #pm is a CompletePathMaker Ross[EMAIL PROTECTED] - [EMAIL PROTECTED](1) Ross [etc] If your nextPath

RE: [R] How to change the value of a class slot

2005-06-07 Thread Berton Gunter
Second, in my experiments I couldn't get setReplacementMethod to work: bumpIndex- - function(pm, value) { [EMAIL PROTECTED] - [EMAIL PROTECTED](value) pm } # I get an error without the next function definition bumpIndex - function(pm) [EMAIL PROTECTED] setReplaceMethod(bumpIndex,

Re: [R] How to change the value of a class slot

2005-06-07 Thread Henrik Bengtsson
Berton Gunter wrote: Second, in my experiments I couldn't get setReplacementMethod to work: bumpIndex- - function(pm, value) { [EMAIL PROTECTED] - [EMAIL PROTECTED](value) pm } # I get an error without the next function definition bumpIndex - function(pm) [EMAIL PROTECTED]

RE: [R] How to change the value of a class slot [INFO]

2005-06-07 Thread Ross Boylan
On Tue, 2005-06-07 at 13:49 -0700, Berton Gunter wrote: Second, in my experiments I couldn't get setReplacementMethod to work: bumpIndex- - function(pm, value) { [EMAIL PROTECTED] - [EMAIL PROTECTED](value) pm } # I get an error without the next function definition

Re: [R] How to change the value of a class slot

2005-06-06 Thread Ross Boylan
On Sat, Jun 04, 2005 at 07:08:56PM +0200, Martin Maechler wrote: Ross nextPath - function(pm){ #pm is a CompletePathMaker Ross[EMAIL PROTECTED] - [EMAIL PROTECTED](1) Ross [etc] If your nextPath function has 'pm' as its last statement it will return the updated object,

Re: [R] How to change the value of a class slot

2005-06-04 Thread Martin Maechler
Ross == Ross Boylan [EMAIL PROTECTED] on Fri, 03 Jun 2005 17:04:08 -0700 writes: Ross I defined an S4 class with a slot i. Then I wrote a regular function Ross that attempted to increment i. Ross This didn't work, apparently because of the general rule that a function

[R] How to change the value of a class slot

2005-06-03 Thread Ross Boylan
I defined an S4 class with a slot i. Then I wrote a regular function that attempted to increment i. This didn't work, apparently because of the general rule that a function can't change the values of its arguments outside the function. I gather there are ways around it, but the Green book