[R] modify function in a package
baccts at hotmail.com
Tue Sep 30 17:55:44 CEST 2014
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
> Subject: Re: [R] modify function in a package
> From: dwinsemius at comcast.net
> Date: Thu, 25 Sep 2014 17:14:30 -0700
> CC: r-help at r-project.org
> To: baccts at 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:
>> 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:
> David Winsemius
> Alameda, CA, USA
More information about the R-help