如何使用同一个R包的多个版本? [英] How do you use multiple versions of the same R package?

查看:297
本文介绍了如何使用同一个R包的多个版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了能够比较一个程序包的两个版本,我需要能够选择要加载的程序包的哪个版本. R的软件包系统默认设置为覆盖现有软件包,因此您始终具有最新版本.如何覆盖此行为?

In order to be able to compare two versions of a package, I need to able to choose which version of the package that I load. R's package system is set to by default to overwrite existing packages, so that you always have the latest version. How do I override this behaviour?

到目前为止,我的想法是:

My thoughts so far are:

我可以获取软件包的来源,编辑描述以给出不同的名称,并有效地构建两个不同的软件包.不过,我宁愿能够直接使用二进制文件,因为麻烦程度要小得多.

I could get the package sources, edit the descriptions to give different names and build, in effect, two different packages. I'd rather be able to work directly with the binaries though, as it is much less hassle.

我不必同时加载两个版本的软件包(只需同时安装在某个位置).我可能会弄混Sys.getenv('R_HOME')来更改R安装软件包的位置,然后.libpaths()来更改R查找软件包的位置.但是,这似乎很hacky,所以有人有更好的主意吗?

I don't necessarily need to have both versions of the packages loaded at the same time (just installed somewhere at the same time). I could perhaps mess about with Sys.getenv('R_HOME') to change the place where R installs the packages, and then .libpaths() to change the place where R looks for them. This seems hacky though, so does anyone have any better ideas?

推荐答案

您可以有选择地更改库路径.为了完全透明,请将两者都放在通常的路径之外,然后执行

You could selectively alter the library path. For complete transparency, keep both out of your usual path and then do

 library(foo, lib.loc="~/dev/foo/v1")    ## loads v1

 library(foo, lib.loc="~/dev/foo/v2")    ## loads v2

当然,对于install.packages()也是一样.所有这些命令都有许多参数,因此您想要的钩子可能已经存在.因此,不要看更改R_HOME,而要看help(install.packages)(假设您从源代码安装).

The same works for install.packages(), of course. All these commands have a number of arguments, so the hooks you aim for may already be present. So don't look at changing R_HOME, rather look at help(install.packages) (assuming you install from source).

但是AFAIK不能以相同的名称两次加载相同的程序包.

But AFAIK you cannot load the same package twice under the same name.

这篇关于如何使用同一个R包的多个版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆