Skip to content

Calling R functions with multiple arguments from C

2 messages · Rossouw, Ruan (RF), Brian Ripley

#
Try PrintValue(R_fcall):

function(x,y)match.call()
(list(x = 10, y = 12))

You want a pairlist of length 1+nargs, not a pairlist of pairlists.  Here 
is one way to do it (there are many)

#include <Rinternals.h>

SEXP foo(SEXP fn, SEXP elmt1, SEXP elmt2, SEXP rho)
{
     SEXP R_fcall, args, ans,s;
     PROTECT( R_fcall = lang3(fn, elmt1, elmt2) );
     s = CDR(R_fcall);
     SET_TAG(s, install("x"));
     s = CDR(R_fcall);
     SET_TAG(s, install("y"));
     ans = eval(R_fcall, rho);
     UNPROTECT(1);
     return ans;
}
On Thu, 24 Apr 2008, Rossouw, Ruan (RF) wrote: