Message-ID: <497998B8.1090903@pburns.seanet.com>
Date: 2009-01-23T10:15:20Z
From: Patrick Burns
Subject: how to get a primitive function object
In-Reply-To: <a0428ec90901221350l76bc20fao4e44f4bb8b90655f@mail.gmail.com>
If I understand properly, you want '<-' to be
a generic function, which it currently isn't.
There may be a way to fake that (I can't think
of any).
But I'm wondering if you should rethink what
you want. The only reason that I can think of
that you would want to change '<-' is because
of some extra side effect that you want to happen.
That is not in the spirit of R.
Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of "The R Inferno" and "A Guide for the Unwilling S User")
Yi Zhang wrote:
>> i was sort-of joking, though it's a real option if you want it.
>>
>> but seriously, there's no reason for the &%#* lamenting:
>>
>> x <- 1
>> '<-' = function(x,y) 0
>> x <- 2
>> # 0
>>
>> .Primitive('<-')(x,2)
>> x
>> # 2
>>
>> base::'<-'(x, 3)
>> x
>> # 3
>>
>> base::'<-'('<-', base::'<-')
>> x <- 4
>> x
>> # 4
>>
>> vQ
>>
>>
>
> I'm still not sure if this can help solve my problem. If I want to
> overwrite the `<-` operator for a particular type of objects, but
> preserve its effect for other regular objects (in other words, if I do
> x<-5 with my new <-, x will be 5 and nothing strange happens), then
> what should I put in the [ ] below?
> old <- `<-`
> old(`<-`, function(x, value){
> if (value is my type) do something
> [ ] # to bind the object value to symbol x: no matter what you do
> here, the binding/assignment is local within this function?!
> })
>
> Hope I have made myself clear. Thanks,
>