From timb at metrumrg.com  Thu Apr  6 21:46:44 2006
From: timb at metrumrg.com (Tim Bergsma)
Date: Thu, 06 Apr 2006 15:46:44 -0400
Subject: [Rd] prevent reassignment of function names
Message-ID: <44357024.6090804@metrumrg.com>

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?

Thanks,

Tim.

-------------------------------------------------------------
rm(list=ls())
"<-" <- function(x,value){
	try(assign("y",x), silent=TRUE)
	if (exists("y", mode="function"))
		stop("assignment to an existing function")
	else  eval(substitute(.Primitive("<-")(x, value)),sys.frame(sys.parent(2)))
}

MYLEN <- function(infile){
	LEN <- nchar(infile)
	return(LEN)	
}
a <- 3
c <- 3
#Error in c <- 3 : assignment to an existing function
d <- MYLEN("word")
#Error in nchar(infile) : object "infile" not found



[Rd] prevent reassignment of function names
Tim Bergsma