Dear R-devel, A couple of weeks ago I started to use the R C API for package development. Without knowing much about C, I've been able to write some routines sucessfully... until now.
My problem consists in dynamically creating a list ("L1") of lists using .Call, the tricky part is that each element of the "mother list" contains two vectors (INTSXP and REALEXP types) with varying sizes; sizes that I set while I'm looping over another list's ("L1") elements (input list). The steps I've follow are: FIRST: Create the "mother list" of size "n=length(L0)" (doesn't change) and protect it as PROTECT(L1=allocVector(VECEXP, length(L0))) and filling it with vectors of length two: for(i=0;i<n;i++) SET_VECTOR_ELT(L1,i, allocVector(VECSXP, 2)); then, for each element of the mother list: for(i=0;i<n;i++) { SECOND: By reading this post in Stackoverflow http://stackoverflow.com/questions/7458364/growing-an-r-matrix-inside-a-c-loop/7458516#7458516 I understood that it was necesary to (1) create the "child lists" and protecting them with PROTECT_WITH_INDEX, and (2) changing its size using SETLENGTH (Rf_lengthgets) and REPROTECT ing the lists in order to tell the GC that the vectors had change. THIRD: Once my two vectors are done ("id" and "lambda"), assign them to the i-th element of the "mother list" L1 using SET_VECTOR_ELT(VECTOR_ELT(L1,i), 0, duplicate(id)); SET_VECTOR_ELT(VECTOR_ELT(L1,i), 1, duplicate(lambda)); and unprotecting the elements protected with index: UNPROTECT(2); } FOURTH: Unprotecting the "mother list" (L1) and return it to R With small datasets this works fine, but after trying with bigger ones R (my code) keeps failing and returning a strange error that I haven't been able to identify (or find in the web) "unimplemented type (29) in 'duplicate'" This happens right after I try to use the returned list from my routine (trying to print it or building a data-frame). Does anyone have an idea of what am I doing wrong? Best regards, PS: I didn't wanted to copy the entire function... but if you need it I can do it. George Vega Yon +56 9 7 647 2552 http://ggvega.cl ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel