[Rcpp-devel] calling Rf_initEmbeddedR error

Young-Ju Park yjpark.10897 at gmail.com
Wed Sep 8 11:56:15 CEST 2010


Hi all,

I have a problem of Rf_initEmbeddedR function.

I've tried with:
 try
 {
  int Argc1 = 1;
  char *Argv1[] = {"Rtest_1"};
  int Argc2 = 1;
  char *Argv2[] = {"Rtest_2"};

  // Init R(first)
  Rf_initEmbeddedR(Argc1, Argv1);

  // R package load
  SEXP e = R_NilValue;
  SEXP r = R_NilValue;
  PROTECT(e = lang2(install("source"), mkString("hreg.r")));
  r = R_tryEval(e, R_GlobalEnv, NULL);     // -----> success
  UNPROTECT(1);
  // Function load
  SEXP fun;
  PROTECT(e = allocVector(LANGSXP, 3));
  fun = findFun(install("hreg"), R_GlobalEnv);
  if(fun == R_NilValue)                   // -----> success
  {
   UNPROTECT(1);
   throw std::range_error("R Function not found");
  }
  SETCAR(e, fun);
  UNPROTECT(1);

  // End R
  R_dot_Last();
  Rf_endEmbeddedR(0);
   R_gc();

  /////////////////////////////
  // Init R(second)
  Rf_initEmbeddedR(Argc2, Argv2);

  // R package load
  e = R_NilValue;
  r = R_NilValue;
  PROTECT(e = lang2(install("source"), mkString("hbnreg.R")));
  r = R_tryEval(e, R_GlobalEnv, NULL);    // -----> NULL return
  UNPROTECT(1);
  // Function load
  PROTECT(e = allocVector(LANGSXP, 3));
  fun = findFun(install("hbnreg"), R_GlobalEnv);   // -----> Exception Error
  if(fun == R_NilValue)
  {
   UNPROTECT(1);
   throw std::range_error("R Function not found");
  }
  SETCAR(e, fun);
  UNPROTECT(1);

  // End R
  R_dot_Last();
  Rf_endEmbeddedR(0);
   R_gc();
 }
 catch(std::exception& ex)
 {
  m_strErrMsg = ex.what();
  return S_FALSE;
 }
 catch(...)
 {
  m_strErrMsg = "Exception: unknown reason";
  return S_FALSE;
 }

-----------------------------
my work environment :
R version : 2.11.1
Development Language : VC++
OS : WinXP Pro sp3

Thanks and best regards.

Young-Ju, Park
from Korea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20100908/0a85c990/attachment-0001.htm>


More information about the Rcpp-devel mailing list