[Rd] .Call question

From: Rossi, Peter E. <Peter.Rossi_at_chicagogsb.edu>
Date: Wed 26 Jul 2006 - 20:36:03 GMT

 

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 Received on Thu Jul 27 06:45:11 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 27 Jul 2006 - 00:31:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.