1

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
landau
  • 5,636
  • 1
  • 22
  • 50
  • ?? I think you have a typo in your code. Should be `is.namespace(environment(ggplot2::ggplot))` – G5W Mar 10 '18 at 23:18

1 Answers1

1

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

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89