[Rd] Sending lists using .C

Brian G. Peterson brian at braverock.com
Sun Apr 22 12:08:53 CEST 2012


On Sat, 2012-04-21 at 17:49 -0700, chris90nz wrote:
<...>
> I have written the following code which will let me pass it through
> using .C
> as two vectors, one containing the numbers contained in the lists all
> concatenated, the other containing the indicies at which each list
> starts.
<...>
> This approach works, but is still slow (10,000 times doing this takes
> ~30seconds).
> 
> I know you can pass a list through by having the C function take as a
> parameter SEXP*. However I am not familiar with using Rinternals.h and
> am a little lost as to how I would access elements of my big list if I
> just pass the whole thing through to a SEXP*.
> 
> The other thing is I have 2 lists to pass through like this, and
> another with an arbitrary sized matrix instead of a list of integers,
> so I think the only way I can do this efficiently is if I do pass
> these lists through to a SEXP*.

The fact that you admit to being  'a little lost' suggests that you
should use a higher level interface.  The list archives here have a
wealth of information, most recently a very good summary of the more
modern .Call interface here:
http://www.mail-archive.com/r-devel@r-project.org/msg26578.html
and here:
http://www.mail-archive.com/r-devel@r-project.org/msg26631.html

as an even higher level interface, perhaps you should consider RCpp,
which contains even more data structures for handling large R data
structures, and more hand holding.  Reference slides here:
http://dirk.eddelbuettel.com/bio/presentations.html
(see especially the full day workshop from 2010)

Regards,

   - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-devel mailing list