/* Obtain an R object via its name. * This is only used to get the 'get' function. * All subsequent calls go via the 'get' function itself */ VALUE get_fun(VALUE self, VALUE name){ VALUE str; int conversion=TOP_MODE; SEXP robj; VALUE rubyobj; char* cstr_name; str = StringValue(name); cstr_name = RSTRING_PTR(str); robj = (SEXP)get_fun_from_name(cstr_name); if (!robj) return Qnil; /* Wrap the returned R object as a ruby Object */ rubyobj = Data_Wrap_Struct(rb_const_get(rb_cObject, rb_intern("RObj")), 0, &Robj_dealloc , robj); rb_iv_set(rubyobj,"@conversion",INT2FIX(conversion)); rb_iv_set(rubyobj,"@wrap",Qfalse); return rubyobj; }
/* Evaluate a function given by a name (without arguments) */ SEXP do_eval_fun(char *name) { SEXP exp, fun, res; fun = get_fun_from_name(name); if (!fun) return NULL; PROTECT(fun); PROTECT(exp = allocVector(LANGSXP, 1)); SETCAR(exp, fun); PROTECT(res = do_eval_expr(exp)); UNPROTECT(3); return res; }
SEXP eval_Rfunc(char *fname) { SEXP expr, func, res; func = get_fun_from_name(fname); if (!func) return NULL; PROTECT(func); PROTECT(expr = allocVector(LANGSXP, 1)); SETCAR(expr, func); PROTECT(res = eval_Rexpr(expr)); UNPROTECT(3); return res; }