R - C接口:从环境中提取对象。

时间:2021-10-12 15:07:49

Say that you pass an environment R object to an internal C routine through the .Call interface. Said enviromnent has (by design) a someObject object which I want to extract and manipulate from the C side. How to do it?

假设您通过. call接口将环境R对象传递给内部C例程。说环境(设计)是一个我想从C方面提取和操作的物体。如何去做?

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

为了简化问题,我只想写一个返回某个对象的C函数。是这样的:

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

Guess the C code should then look something like

我猜C代码应该是这样的

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

Unfortunately, I was not able to find the real SOMEMACROORFUNCTION.

不幸的是,我没能找到真正的顶体功能。

1 个解决方案

#1


3  

After a little bit of googling and searching, I've found the solution:

在谷歌和搜索了一段时间之后,我找到了解决方案:

findVar(install("someObject"),env)

in the C code is basically the equivalent of get("someObject",env) in R.

在C代码中,基本上等同于R中的get(“someObject”,env)。

#1


3  

After a little bit of googling and searching, I've found the solution:

在谷歌和搜索了一段时间之后,我找到了解决方案:

findVar(install("someObject"),env)

in the C code is basically the equivalent of get("someObject",env) in R.

在C代码中,基本上等同于R中的get(“someObject”,env)。