How to unmask a function in R, due to name collisions on searchpath

▼魔方 西西 提交于 2019-11-29 18:56:55

问题


When I loaded package debug to debug a script with zoo objects, I got trouble: function index from zoo got masked by debug package. How can I unmask index? In general, how to deal with these name colliding problems? We just do not use debug package with `zoo'?


回答1:


Exported symbols are always identifiable with the :: operator:

zoo::index

Hidden functions not declared in the namespace can still be accessed using ::: (triple-colon), and example would be

zoo:::.onLoad

which you can see even though it is not exported.




回答2:


You can unload the package which has masked functions and then reload it. It will regain precedence in the searchpath:

unloadNamespace("zoo")
library("zoo")

In the future, if you want to load a package while preventing it from masking other functions, you can specify its position in the search path with an arbitrary large number:

library("debug", pos = .Machine$integer.max)



回答3:


Its only masked to you but its not masked to zoo so when a zoo function tries to use index it will still find its own index first.

zoo also has a time.zoo method so if z is a zoo object you can use time(z) in place of index(z).

Finally you can always refer to zoo::index to make sure you get the one in zoo.



来源:https://stackoverflow.com/questions/3241539/how-to-unmask-a-function-in-r-due-to-name-collisions-on-searchpath

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