[Rcpp-devel] Copying a NumericVector from a list within a list

Krzysztof Sakrejda krzysztof.sakrejda at gmail.com
Sun Apr 13 17:12:23 CEST 2014


On Sat, Apr 12, 2014 at 11:06 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
> What can work as a single expression in R sometimes needs to be disentangled
> at the C++ level to help the compiler find its way through all the templates.
>
[snip]
>
> // [[Rcpp::export]]
> NumericVector fromList(List outer, std::string name) {
>   List inner = outer[0];                // 0-based offsets in C++
>   return inner["p"];
> }

I've noticed (I think...) having to do this sort of thing, but I want
to ask a question to clarify: is it possible to have the above code
work, but if you instead try:

NumericVector fromList(List outer, std::string name) {
(outer[0])["p"]
}



>
> /*** R
> x <- c(0.2855202, 0.6731716, 0.8497825, 0.7445254, 0.2382722)
> innL <- list(p=x)
> outL <- list(List1=innL)
> fromList(outL, "p")
> */
>
>
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel



-- 

Krzysztof Sakrejda

Organismic and Evolutionary Biology
University of Massachusetts, Amherst
319 Morrill Science Center South
611 N. Pleasant Street
Amherst, MA 01003

work #: 413-325-6555
email: sakrejda at cns.umass.edu
-----------------------------------------------


More information about the Rcpp-devel mailing list