From deepayan.sarkar at gmail.com  Sun Oct 22 21:56:31 2006
From: deepayan.sarkar at gmail.com (Deepayan Sarkar)
Date: Sun, 22 Oct 2006 12:56:31 -0700
Subject: [Rd] Getting hold of a package's environment from C code
Message-ID: <eb555e660610221256g3952a408sc25f06afe8307cb5@mail.gmail.com>

Hi,

I have a package where I'm calling an R function (say "foo") from C
code. "foo" is in the same package, but is not exported. I construct
the call using lang1(install("foo")), but to eval it I need the
package's environment.  Is there a way to do this? Passing the correct
environment through .Call() is not an option.

Right now, I'm getting the environment first using something like

  rho = PROTECT(eval(lang2(install("environment"), install("bar")),
R_GlobalEnv))

where bar _is_ exported. However, this doesn't work if the package is
loaded but not attached, and is also risky because someone might
define another "bar" that is found first.

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?

-Deepayan




[Rd] Getting hold of a package's environment from C code
Deepayan Sarkar