[R] how to get a primitive function object

Yi Zhang yizhang84 at gmail.com
Thu Jan 22 21:29:32 CET 2009


On Thu, Jan 22, 2009 at 3:06 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>
> get("<-") will give it to you, and
>
> `<-` <- function(x, y) cat("x=", x, "y=", y, "\n")
>
> will change it -- and will probably be the last effective thing you do in
> that session, unless you're really careful:
>
>> x <- 1
>> x
> [1] 1
>> `<-` <- function(x, y) cat("x=", x, "y=", y, "\n")
>> x <- 3
> x= 1 y= 3
>> x
> [1] 1
>> # now what?? &%#*
>> q("no")
>
> Duncan Murdoch
>

Thanks for the replies! Actually I have thought about this; what I
plan to do is:
oldAssign <- `<-`
oldAssign(`<-`, function(x,value){if (...) do_something; oldAssign(x,value)})
x<-1
x # object not found!!
So the problem now is the effect of oldAssign(x,value) is only
local--within that anonymous function. Is there a way to do
assignInNamespace (or how to get the namespace where the overridden <-
is called)?




More information about the R-help mailing list