From term at blueyonder.co.uk  Fri Oct 27 13:11:45 2006
From: term at blueyonder.co.uk (Tom McCallum)
Date: Fri, 27 Oct 2006 12:11:45 +0100
Subject: [Rd] Overloading functions
Message-ID: <op.th2upvilmfjo24@norisk>

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




[Rd] Overloading functions
Tom McCallum