R package installed in 2 different locations

空扰寡人 提交于 2021-02-20 02:25:12

问题


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

in ape version 3.4, there is a new function clustalomega. I have NOT loaded any of the 2 packages (using library)

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.

I have tried to reverse the order of the libPath, with .libPath(rev(.libPath()) but it didn't change anything.

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)


回答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 # doesn't exist
'ape' %in% loadedNamespaces() #returns TRUE
unloadNamespace(ns = 'ape') 'ape' %in% loadedNamespaces() #returns FALSE loadNamespace(package = 'ape', lib.loc = location2)

ape::clustalomega # now works



来源:https://stackoverflow.com/questions/34217269/r-package-installed-in-2-different-locations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!