Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one create a new R environment from C?

Tags:

c

r

I wasn't able to find documentation for this. It looks like the R source code uses NewEnvironment and R_NewHashedEnv, but neither of those are in the public headers, so it looks like they aren't available for me as a user. What function (or what lines of code) should I be using to generate a new ENVSXP?

like image 509
bk. Avatar asked Feb 09 '12 19:02

bk.


1 Answers

You want allocSExp:

/* C code in foo.c */
#include "Rinternals.h"
SEXP foo() {
  SEXP res = allocSExp(ENVSXP);
  return res;
}

> # R code (after running R CMD SHLIB foo.c)
> dyn.load("foo.dll")
> .Call("foo")
<environment: 0x016a4084>
like image 155
Joshua Ulrich Avatar answered Oct 21 '22 17:10

Joshua Ulrich