[Rcpp-devel] add new components to list without specifying list size initially

Walrus Foolhill walrus.foolhill at gmail.com
Sat Aug 13 17:35:05 CEST 2011


Steve and Dirk, thanks again, I will look into the GenomicRanges package for
my immediate usage, but for my future need, I will also keep trying to
manipulate nested lists with Rcpp, as all my data structures are as such.

On Fri, Aug 12, 2011 at 4:37 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> On 12 August 2011 at 16:26, Walrus Foolhill wrote:
> | Thanks for your advice, I now understand how to manipulate one-level
> lists:
> |
> | fn <- cxxfunction(signature(l_in="list"),
> |                   body='
> | using namespace Rcpp;
> | List l(l_in);
> | IntegerVector lf = l["foo"];
> | CharacterVector lb = l["bar"];
> | for(int i=0; i<lf.size(); ++i)
> |   Rprintf("l[%s][%i] %i\\n", "foo", i, lf[i]);
> | for(int i=0; i<lb.size(); ++i)
> |   Rprintf("l[%s][%i] %s\\n", "bar", i, std::string(lb[i]).c_str());
> | ', plugin="Rcpp", verbose=TRUE)
> | z <- fn(list(foo=c(1,2,3,4),bar=c("bar1","bar2")))
> |
> | But what about 2-level lists? Why the following code doesn't compile?
> |
> | fn <- cxxfunction(signature(l_in="list"),
> |                   body='
> | using namespace Rcpp;
> | List l(l_in);
> | List lf(l["foo"]);
> | ', plugin="Rcpp", verbose=TRUE)
> | z <- fn(list(foo=list(bar=1)))
> |
> | And what the following message mean? "error: call of overloaded ‘Vector
> | (Rcpp::internal::generic_name_proxy<19>)’ is ambiguous"
> |
> | I had a look at "runit.Vector.R" on r-forge, but couldn't find any test
> | involving 2-level (or more) lists, although on SO in June 2010 (http://
> |
> stackoverflow.com/questions/3088650/how-do-i-create-a-list-of-vectors-in-rcpp/
> | 3088744#3088744), you said that it should work.
> |
> | I checked that I can create a 2-level list, but the code below doesn't
> compile
> | if I uncomment the last Rprintf line:
>
> There can be times when the C++ templating gets in the way, so if this
> doesn't work in a single statement, decompose it into two (one to assign to
> a
> temp, another to print them temp) and move on.
>
> I have done two-level lists in the past; one key is that a list ... is just
> another SEXP, or can be wrap()'ed to a SEXP, and you can hence assign a
> list
> to be a component of another. And then another and so on...
>
> Dirk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110813/0480f3fa/attachment.htm>


More information about the Rcpp-devel mailing list