David, thank you for pointing me in the right direction!

For the record, I was able to override the NanoStringNorm function while still 
calling other functions in the package using the following:
source('my.nanostringnorm.R") # inside my.nanostringnorm.R, my modified 
function is called NanoStringNorm
assignInNamespace('NanoStringNorm',NanoStringNorm,ns='NanoStringNorm')
environment(NanoStringNorm)<-asNamespace('NanoStringNorm');

----------------------------------------
> Subject: Re: [R] modify function in a package
> From: dwinsem...@comcast.net
> Date: Thu, 25 Sep 2014 17:14:30 -0700
> CC: r-help@r-project.org
> To: bac...@hotmail.com
>
>
> On Sep 25, 2014, at 11:21 AM, C Lin wrote:
>
>> Dear R users,
>> There is a package called NanoStringNorm with a function called 
>> NanoStringNorm.
>> What I want to do is to change the NanoStringNorm function from the package 
>> with my own copy that is written in my.nanostringnorm.R.
>> But if I do the following:
>>
>> source('my.nanostringnorm.R")
>> unlockBinding("NanoStringNorm", as.environment("package:NanoStringNorm")) ;
>> assign("NanoStringNorm", NanoStringNorm, "package:NanoStringNorm") ;
>>
>> Although, it now correctly called my NanoStringNorm, it doesn't recognize a 
>> function called inside my NanoStringNorm that called another functions in 
>> the NanoStringNorm package.
>> So, I have to change all such functionswith NanoStringNorm:::function.name.
>> How should I replace the NanoStringNorm function but still able to call 
>> other function in the package?
>> I still have package NanoStringNorm in my search path but somehow it can't 
>> find the other function.
>
> Take a look at assignInNamespace. It's also possible to set the environment 
> of a function:
>
> ?assignInNamespace
> ?`environment<-`
>
>
> --
> David Winsemius
> Alameda, CA, USA
>
                                          
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to