[Rd] prevent reassignment of function names

From: Tim Bergsma <timb_at_metrumrg.com>
Date: Thu 06 Apr 2006 - 19:46:44 GMT


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

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Apr 07 07:22:32 2006

This archive was generated by hypermail 2.1.8 : Fri 07 Apr 2006 - 00:17:36 GMT