Reputation: 52637
I'm looking to fetch what would be the lib.loc
argument to library
or loadNamespace
, from a currently loaded namespace.
For attached packages this is relatively straightforward:
path.package("stats") # get library location of loaded stats package
However, for a non-attached loaded namespace, the best I can come up with is:
getNamespace(x)[[".__NAMESPACE__"]][["path"]]
which happens to work on my R version, but has absolutely no guarantee of working in the future. I could also temporarily attach the package to use path.package
, but that would potentially trigger attach hooks and I'd prefer to avoid that.
Anyone know of an equivalent to path.package
for loaded but not attached namespaces?
Upvotes: 4
Views: 300
Reputation: 121568
You can use find.package
:
it returns path to the locations where the given packages are found. If lib.loc is NULL, then loaded namespaces are searched before the libraries.
Upvotes: 3