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

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to