R软件包安装在2个不同的位置 [英] R package installed in 2 different locations
问题描述
我在2个位置安装了R软件包 ape
,它们都是 .libPath()
的一部分-location1中的 ape
版本3.3
-location2中的 ape
版本3.4
I have R package ape
installed in 2 locations, that are BOTH part of the .libPath()
- ape
version 3.3 in location1
- ape
version 3.4 in location2
在 ape
版本3.4中,有一个新函数 clustalomega
.我尚未加载2个软件包中的任何一个(使用 library
)
in ape
version 3.4, there is a new function clustalomega
. I have NOT loaded any of the 2 packages (using library
)
ape :: clustalomega
在我的计算机上不起作用.我怀疑这是因为R首先考虑了它在location1中发现的 ape
的旧版本.
ape::clustalomega
doesn't work on my machine. I suspect it comes from the fact that R is considering first the old version of ape
it has found in location1.
我尝试使用 .libPath(rev(.libPath())
颠倒libPath的顺序,但是它没有任何改变.
I have tried to reverse the order of the libPath, with .libPath(rev(.libPath())
but it didn't change anything.
有没有办法确保我们从位置2优先处理该软件包(我无法控制位置1上安装的内容)
Is there a way to ensure we take the package in priority from location 2 (I have no control on what is installed on location1)
推荐答案
解决方案在于函数 unloadNamespace
.看起来,当R启动时,即使它没有加载 library("ape")
,它仍会从第一个lib.loc找到该包的名称空间(在这种情况下,,位置1)
The solution lies with function unloadNamespace
. It seems that when R is starting, eventhough it is not loading the library("ape")
, it still loads the namespace of the package, from the first lib.loc it can find (in this case, location1)
因此,为了强制从另一个位置加载名称空间,我们需要这样做:
So in order to force the loading of the namespace from another location, we need to do:
ape :: clustalomega#不存在
'ape'%in%loadNamespaces()#返回TRUE
unloadNamespace(ns ='ape')'ape'%in%loadNamespaces()#返回FALSEloadNamespace(package ='ape',lib.loc = location2)
ape::clustalomega # doesn't exist
'ape' %in% loadedNamespaces() #returns TRUE
unloadNamespace(ns = 'ape') 'ape' %in% loadedNamespaces() #returns FALSE loadNamespace(package = 'ape', lib.loc = location2)
ape :: clustalomega#现在可以使用
ape::clustalomega # now works
这篇关于R软件包安装在2个不同的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!