From tom.mccallum at levelelimited.com  Fri Oct 27 17:09:01 2006
From: tom.mccallum at levelelimited.com (Tom McCallum)
Date: Fri, 27 Oct 2006 16:09:01 +0100
Subject: [Rd] Overloading functions
In-Reply-To: <op.th241errmfjo24@norisk>
References: <op.th2upvilmfjo24@norisk>
	<Pine.OSF.4.58.0610270842350.65414@wotan.mdacc.tmc.edu>
	<op.th241errmfjo24@norisk>
Message-ID: <op.th25pbxdffxks9@norisk>

On Fri, 27 Oct 2006 15:54:40 +0100, Tom McCallum <term at blueyonder.co.uk>  
wrote:

> On Fri, 27 Oct 2006 14:49:15 +0100, Paul Roebuck <roebuck at mdanderson.org>
> wrote:
>
>> On Fri, 27 Oct 2006, Tom McCallum wrote:
>>
>>> 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?
>>
>> ?environment
>>
>> ----------------------------------------------------------
>> SIGSIG -- signature too long (core dumped)
>>
>>
>
> Thanks for that, have almost figured out how to do it,  have got my
> namespace but when I "assign" the new value
> I get "cannot change value of a locked binding".  Is there any way to say
> that a particular item in a package
> is able to be overridden using assign?
>
> I assume when I export a function in the NAMESPACE file it is locking the
> value to the name.  So I assume it is here I need
> to change something - if this is even possible to do.
>
> Cheers
>
> Tom
>
  found the use of assignInNamespace - done!

Thanks for your help.




[Rd] Overloading functions
Tom McCallum