[R] calling Rf_initEmbeddedR error
나여나
dllmain at hanmail.net
Thu Sep 9 03:15:09 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
[1][rKWLzcpt.zNp8gmPEwGJCA00]
[@from=dllmain&rcpt=r%2Dhelp%40r%2Dproject%2Eorg&msgid=%3C20100909101509%2EH
M%2E0000000000000eJ%40dllmain%2Ewwl737%2Ehanmail%2Enet%3E]
References
1. mailto:dllmain at hanmail.net
More information about the R-help
mailing list