Reputation: 5841
I am looking for a way to detect if an environment is a package namespace. Desired behavior:
is.namespace(environment(data.frame))
## [1] TRUE
is.namespace(environment(ggplot2::ggplot))
## [1] TRUE
is.namespace(globalenv())
## [1] FALSE
is.namespace(new.env(parent = globalenv()))
## [1] FALSE
Upvotes: 1
Views: 210
Reputation: 9656
Turns out there is such a function. But for reasons that I don't understand it is named isNamespace
instead of is.namespace
.
> isNamespace(environment(data.frame))
[1] TRUE
More information can also be found in the related question here: How to distinguish package namespace environment from other environment objects
Upvotes: 1