Skip to content
Prev 22509 / 63421 Next

Getting hold of a package's environment from C code

On 10/22/2006 3:56 PM, Deepayan Sarkar wrote:
In R code, you could use getNamespace("pkg") to get the namespace 
environment.  I haven't tried this, but I'd assume

PROTECT(rho = eval(lang2(install("getNamespace"),
                          ScalarString(mkChar("pkg"))));

(or something like it) would be the C equivalent.

 >
 > One solution that might work is to make 'rho' a global variable and
 > assign the correct value when the package is loaded. Is that a good
 > idea? How should I PROTECT it?

I'd say to avoid globals if you can, and I think you can here.

Duncan Murdoch