问题描述
一些背景:
我必须大量使用软件包HMR
中的函数HMR
.不幸的是,此功能非常慢. (HMR
本质上是一种拟合函数,被设计为尽可能强健,这是效率不足的原因之一.)函数HMR
调用函数HMR::.HMR.fit1
,该函数进行实际拟合.使用Rprof
我知道关于效率的主要问题是使用lsfit
的方法,这引起了很多关注.因此,我修改了.HMR.fit1
的代码以直接调用lsfit
所使用的C函数,而没有lsfit
的所有开销,这应该会带来可观的速度提升.
I have to use function HMR
from package HMR
a lot. Unfortunately, this function is very slow. (HMR
is essentially a fitting function, which is designed to be as robust as possible, which is one reason for the lack of efficiency.) Function HMR
calls function HMR::.HMR.fit1
, which does the actual fitting.Using Rprof
I know that the main problem regarding efficiency is the use of lsfit
, which gets called a lot. Therefore, I modified the code of .HMR.fit1
to call the C function used by lsfit
directly without all the overhead of lsfit
, which should result in a substantial speed gain.
现在,我想用修改后的功能替换HMR::.HMR.fit1
并测试HMR
,如果它给出相同的结果以及我获得多少速度.
Now I would like to substitute HMR::.HMR.fit1
with my modified function and test HMR
if it gives the same results and how much speed I gain.
我试图这样做:
mod.fun <- function(<many args>) {
<a lot of code>
}
environment(mod.fun) <- environment(.HMR.fit1)
.HMR.fit1 <- mod.fun
但是,HMR::.HMR.fit1
并没有因此改变,并且显然HMR::HMR
没有使用我修改后的拟合函数.有没有一种方法可以在不从源代码构建软件包的情况下实现我想要的功能,由于(Windows)计算机上的用户权限限制,我不能这样做?
However, HMR::.HMR.fit1
is not changed by doing this and apparently HMR::HMR
does not use my modified fitting function. Is there a way to achieve what I want without building the package from source, which I cannot do due to user rights restrictions on my (windows) computer?
现在,我的解决方案是复制HMR::HMR
的代码,但我希望有一个更方便的解决方案.
Right now, my solution would be to copy the code of HMR::HMR
, but I hope there is a more convenient solution.
推荐答案
尝试
?assignInNamespace
用您的版本替换HMR
软件包中的.HMR.fit1
.
to replace .HMR.fit1
in the HMR
package with your version.
可能的副本:
这篇关于变更套件的内部功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!