[Rd] overwriting '<-' and infinite recursions

Yi Zhang yizhang84 at gmail.com
Sat Jan 24 21:54:06 CET 2009


On Fri, Jan 23, 2009 at 5:28 PM,  <luke at stat.uiowa.edu> wrote:
> On Fri, 23 Jan 2009, Yi Zhang wrote:
>
>> Thanks, Luke. I would certainly be very happy to see any non-intrusive
>> solution. The problem I'm dealing with is: I'm creating a new class
>> which references some external resource (file or database) and I want
>> to make the reference counting work. An example (-> means references):
>> Initially we have symbol a -> object oa of my class -> file fa.
>> Suppose then R code "b<-a" is executed. With no modification to the
>> '<-' function, R would make another symbol b and bind it to oa.
>> Imagine next "b[1]<-0" is executed. Here comes the trouble: R only
>> knows to duplicate oa to another ob; the modification will be done to
>> the underlying shared file fa. Of course, I have necessary code for
>> overriding "[<-" and make that modification. The whole thing is
>> because I'm not aware of any sharing of the external resource at the R
>> level. That's the motivation for me to
>> overwrite '<-' in the first place. Any potential alternative solutions?
>
> I'm still fuzzy about what you are trying to accomplish.  You have
> some code, say openFA(), that produces the oa value with
>
>   a <- openOA()
>
> Then you could do
>
>   b <- a
>
> and then
>
>   b[1] <- 0
>
> or
>
>   a[1] <- 0
>
> Do you want these to have the same effect, do you want a[1] <- 0 to do
> one thing if b <- a has happened and another if not, should one signal
> an error, ...?

Yes, I want to do something extra if b<-a has happened.
>
> From what you have written so far it would seem that messing with <-
> would't really help as
>
>   d <- list(a)
>
> and
>
>   f <- fuction(b) { ... }
>   f(a)
>
> would create similar issues that would not be addressed.

I guess you're right... Argument passing is another kind of duplicate
and I don't know how to track this kind of sharing...


-- 
Yi



More information about the R-devel mailing list