Re: [Rd] prevent reassignment of function names

From: Thomas Lumley <>
Date: Thu 06 Apr 2006 - 20:44:50 GMT

On Thu, 6 Apr 2006, Tim Bergsma wrote:

> Hi.
> I'm trying to find a systematic way to prevent assignment to names of
> existing functions. I've tried reassigning to the assignment operator,
> with mixed results. The function definition for "<-" below works as
> hoped for the demonstrated assignments to a and c. However, for the
> assignment based on the test function, it appears that the formal
> argument is not visible. Any suggestions?

Well, my first suggestion would be not to do it. I don't see any real benefit, and messing around with something as basic as assignment is likely to break something. If nothing else, there is certainly code out there where people have, say, "df" or "c" as a variable name, and it isn't doing any harm.

As a programming exercise it seems that the following works

"<-" <- function(x,value){

         if(tryCatch(is.function(x),error=function(e) FALSE))
                 stop("assignment to an existing function")
         else  eval.parent(substitute(.Primitive("<-")(x,value)))


Thomas Lumley			Assoc. Professor, Biostatistics	University of Washington, Seattle

______________________________________________ mailing list Received on Fri Apr 07 07:09:43 2006

This archive was generated by hypermail 2.1.8 : Thu 06 Apr 2006 - 22:17:14 GMT