本文介绍了变更套件的内部功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些背景:

我必须大量使用软件包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.

可能的副本:

如何覆盖包名称空间中有不可见的函数?

这篇关于变更套件的内部功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:19