Try getting the parent environment of your env instead of the environment itself.
This seems to work at least for a simple example I'm installing using devtools
, so who knows what tricks Hadley does with environments in there:
> parent.env(myEnv)
<environment: namespace:Test>
> getPackageName(parent.env(myEnv))
[1] "Test"
This doesn't work for other objects defined in the package:
> foo
function(){
}
<environment: namespace:Test>
> getPackageName(parent.env(foo))
Error in parent.env(foo) : argument is not an environment
you just have to get the environment thus:
> getPackageName(environment(foo))
[1] "Test"