From Peter.Rossi at chicagogsb.edu  Wed Jul 26 22:36:03 2006
From: Peter.Rossi at chicagogsb.edu (Rossi, Peter E.)
Date: Wed, 26 Jul 2006 15:36:03 -0500
Subject: [Rd] .Call question
Message-ID: <1E7B167439290641966EB161D4330798013F4386@GSBEX.gsb.uchicago.edu>

 
Writing R Ext says to treat R objects that are arguments to .Call as
read only (i.e. don't modify). 

I have a long list of lists that and I want to avoid the overhead of a
copy in my C code.  I would just like to modify some of the elements 
of list by replacing them with elements of exactly the same size/type.

below is an example of the essence of the problem.  This seems to work.
Is this dangerous or ok? (of course, I want to do something more
complicated
since I can do this in R, but I hope this illustrates my question).


SEXP modlist(SEXP list, SEXP ind, SEXP element){
   int index;
   index=INTEGER_VALUE(ind);
   SET_ELEMENT(list,index,element);
return(ind);
}

called in R as in 

lst=list("a","b","c")
element="d"
out=.Call("modlist",lst,1,element)

here the .Call is used just for its effect on lst.

thanks!

peter
 

................................
  Peter E. Rossi
 Joseph T. and Bernice S. Lewis Professor of Marketing and Statistics
 Editor, Quantitative Marketing and Economics
 Rm 353, Graduate School of Business, U of Chicago
 5807 S. Woodlawn Ave, Chicago IL 60637, USA
 Tel: (773) 702-7513   |   Fax: (773) 834-2081



[Rd] .Call question
Rossi, Peter E.