[Rd] Timing of SET_VECTOR_ELT

Terry Therneau therneau at mayo.edu
Mon Apr 1 19:10:06 CEST 2013


Assume a C program invoked by .Call, that returns a list.

  Near the top of the program we allocate space for all the list elements. (It is my habit 
to use "xyz2" for the name of the R object and "xyz" for the pointer to its contents.)

     PROTECT(means2 = allocVector(REALSXP, nvar));
     means = REAL(means2);
     PROTECT(u2 = allocVector(REALSXP, nvar));
     u = REAL(u2);
     PROTECT(loglik2 = allocVector(REALSXP, 2));
     loglik = REAL(loglik2);

     PROTECT(rlist = mknamed(VECSXP, outnames));

Can I assign the individual elements into rlist using SET_VECTOR_ELT at this point, or do 
I need to wait until the end of the program, after I've filled in means[i], u[i], etc.?  I 
likely depends on whether I'm assigning a pointer or a copy.


Terry T.



More information about the R-devel mailing list