[Rd] prevent reassignment of function names

Tim Bergsma timb at metrumrg.com
Thu Apr 6 21:46:44 CEST 2006


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?



"<-" <- 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)
a <- 3
c <- 3
#Error in c <- 3 : assignment to an existing function
d <- MYLEN("word")
#Error in nchar(infile) : object "infile" not found

More information about the R-devel mailing list