From ltordsen at mymachinery.net  Sat Apr 16 23:37:32 2005
From: ltordsen at mymachinery.net (Larry Tordsen)
Date: Sat Apr 16 23:37:42 2005
Subject: [Rd] SET_LENGTH
Message-ID: <20050416213732.87710.qmail@web303.biz.mail.mud.yahoo.com>

Hello.

I'm trying to read a delimited file.  I'm a little new
to the R api.  In the program, I do something like
this...

/*****************************/
SEXP retval;
PROTECT(retval = allocMatrix(STRSXP,1,names.dim));
int r_eltctr = 0;
while(!myfile.eof())
{
  SET_LENGTH(retval,r_eltctr+num_of_fields);
  for(int i = 0;numofcolumns; ++i)
    {
      INTEGER(retval)[r_eltctr++] = 1;/*some
value...*/
    }
  ++r_eltctr;
}
UNPROTECT(1);
/***************************************/

There is a segmentation fault when SET_LENGTH() is
called several iterations into the program.  It seems
like it should not be a memory issue, unless a
constraint is set by R.  The vector only has about
3500 elements at the time it crashes.

Does anyone have any ideas what the problem could be?


[Rd] SET_LENGTH
Larry Tordsen