Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'?

like image 998
ahala Avatar asked Jul 13 '10 21:07

ahala


People also ask

What is name masking in R?

Order of Loading Packages in RIf two packages use the same function name, then the package loaded last will hide the function from earlier packages. This is called masking.

What does it mean when a variable is masked in R?

Because R is developed by an open source community, it is not uncommon that multiple packages may use the same name for a function or dataset. If you load packages that use the same name for an object, R will warn that certain object(s) have been “masked”.


2 Answers

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)
like image 109
Lionel Henry Avatar answered Nov 15 '22 19:11

Lionel Henry


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.

like image 32
Dirk Eddelbuettel Avatar answered Nov 15 '22 20:11

Dirk Eddelbuettel