[R] lang2(...) with two and more arguments
    Peter Dalgaard 
    p.dalgaard at biostat.ku.dk
       
    Mon Nov  3 17:06:37 CET 2003
    
    
  
"Timur Elzhov" <elzhov at mail.ru> writes:
> Dear R-help,
> 
> how could I create an R call in C code using lang2 with 2 and more
> arguments? I tried this code:
> 
> SEXP f(SEXP fn, SEXP rho)
> {
>     SEXP R_fcall, x, y;
> 
>     PROTECT(R_fcall = lang2(fn, R_NilValue));
>     PROTECT(x = allocVector(REALSXP, 1));
>     PROTECT(y = allocVector(REALSXP, 1));
> 
>     REAL(x)[0] = 10;
>     REAL(y)[0] = 20;
> 
>     SETCADR(R_fcall, x);
>     SETCADR(R_fcall, y);
> 
>     UNPROTECT(3);
> 
>     return R_fcall;
> }
> 
> .Call("f", c, new.env()) returns
> 
> `.Primitive("c")(20)', but not `.Primitive("c")(10, 20)',
> as I expected. How can I recieve the disired result?
> 
> Thank you very much.
Hmmm. This is definitely not right:
     SETCADR(R_fcall, x);
     SETCADR(R_fcall, y);
sets the same location first to x, and then to y. I suspect you need 
     SETCADDR(R_fcall, y);
but no guarantees...
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
    
    
More information about the R-help
mailing list