R - C interface: retrieving an object from the environment

Say you are passing an environment

R object to an internal C procedure through an interface .Call

. That said enviromnent

has (by design) an object someObject

that I want to retrieve and process from the C side. How do I do this?

To simplify my question, I just want to write a C function that returns someObject

. Like this:

en <- new.env()
en$someObject <- someValue
.Call("extractObject",en)
#the above should return en$someObject

      

Guess the C code should look something like this:

SEXP extractObject(SEXP env) {
   return SOMEMACROORFUNCTION(env, "someObject");
}

      

Unfortunately I was unable to find a real one SOMEMACROORFUNCTION

.

+3


source to share


1 answer


After doing a little search on search engines and searching, I found a solution:

findVar(install("someObject"),env)

      



in C code is basically equivalent get("someObject",env)

in R.

+3


source







All Articles