From brian at braverock.com  Sun Apr 22 12:08:53 2012
From: brian at braverock.com (Brian G. Peterson)
Date: Sun, 22 Apr 2012 05:08:53 -0500
Subject: [Rd] Sending lists using .C
In-Reply-To: <1335055754110-4577449.post@n4.nabble.com>
References: <1335055754110-4577449.post@n4.nabble.com>
Message-ID: <1335089333.17905.94.camel@brian-desktop>

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 at r-project.org/msg26578.html
and here:
http://www.mail-archive.com/r-devel at 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



[Rd] Sending lists using .C
Brian G. Peterson