Skip to content
Prev 47138 / 63424 Next

Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'"

Gabriel,

While the length (in terms of number of SEXP elements it stores) of L1
doesn't changes, the vectors within L1 do (sorry if I didn't explained
it well before).

The post was about a SEXP object that grows, in my case, every pair of
vectors in L1 (id and lambda) can change lengths, this is why I need
to reprotect them. I populate the i-th element of L1 by creating the
vectors "id" and "lambda", setting the length of these according to
some rule (that's the part where lengths change)... here is a reduced
form of my code:

//////////////////////////////////////// C
////////////////////////////////////////
const int = length(L0);
SEXP L1;
PROTECT(L1 = allocVector(VECSXP,n));
SEXP id, lambda;

// Fixing size
for(i=0;i<n;i++)
  SET_VECTOR_ELT(L1, i, allocVector(VECSXP, 2));

for(i=0;i<n;i++)
{
  // Creating the "id" and "lambda" vectors. I do this in every repetition of
  // the loop.
  PROTECT_WITH_INDEX(id=allocVector(INTSXP, 4), &ipx0);
  PROTECT_WITH_INDEX(lambda=allocVector(REALSXP, 4), &ipx1);

  // ... Some other instructions where I set the value of an integer
  // z, which tells how much do the vectors have to grow ...

  REPROTECT(SET_LENGTH(id,    length(lambda) + z), ipx0);
  REPROTECT(SET_LENGTH(lambda,length(lambda) + z), ipx1);

  // ... some lines where I fill the vectors ...

  // Storing the new vectors at the i-th element of the list
  SET_VECTOR_ELT(VECTOR_ELT(L1, i), 0, duplicate(id));
  SET_VECTOR_ELT(VECTOR_ELT(L1, i), 1, duplicate(lambda));

  // Unprotecting the "id" and "lambda" vectors
  UNPROTECT(2);
}

UNPROTECT(1);

return L1;
//////////////////////////////////////// C
////////////////////////////////////////

I can't set the length from the start because every pair of vectors in
L1 have different lengths, lengths that I cannot tell before starting
the loop.

Thanks for your help,

Regards,

George Vega Yon
+56 9 7 647 2552
http://ggvega.cl


2013/11/5 Gabriel Becker <gmbecker at ucdavis.edu>:

Thread (13 messages)

George Vega Yon Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 4 Gabriel Becker Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 5 Brian Ripley Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 5 George Vega Yon Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 5 Gabriel Becker Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 5 George Vega Yon Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 5 George Vega Yon Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 5 George Vega Yon Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 7 Romain Francois Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 7 George Vega Yon Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 7 Romain Francois Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 7 Romain Francois Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 7 George Vega Yon Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'" Nov 7