[Rd] Overloading functions

Tom McCallum term at blueyonder.co.uk
Fri Oct 27 13:11:45 CEST 2006


Hi Everyone

I have a function f which does something using a function g.  Function f  
is in a library and g has a default stub in the library but will be mainly  
overloaded in a later R script.  For example:

########## In a compiled package 'P' #################
g <- function() {
    cat("Original function g");
}

f <- function( newGsource=NULL ) {
     if( is.null(newGsource) == FALSE ) {
	source( newGsource ); # load new function g
     }	
     g();
     return(1);
}
#####################################################

If I call f() then I get "Original function g".

But I want to overload g so I do the following in the file newg.R:

############### CONTENTS of newg.R ##########################
g <- function() {
    cat("New function g in newg.R");
}
################ END CONTENTS ###############################

and call f( newGsource="newg.R" ) but I still get "Original function g".

Any suggestions?

Tom

-- 
---

Tom McCallum

WWW: http://www.tom-mccallum.com
Tel: 0131-4783393
Mobile: 07866-470257




More information about the R-devel mailing list