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

Anirban Mukherjee anirban.mukherjee at gmail.com
Mon Apr 14 12:42:36 CEST 2014


This works:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector fromList(List outer, std::string name) {
    return (as <List> (outer[0]) [name]);
}

/*** R
x <- c(0.2855202, 0.6731716, 0.8497825, 0.7445254, 0.2382722)
innL <- list(p=x)
outL <- list(List1=innL)
fromList(outL, "p")
*/

> sourceCpp("~/Desktop/dion.cpp")
> x <- c(0.2855202, 0.6731716, 0.8497825, 0.7445254, 0.2382722)
> innL <- list(p=x)
> outL <- list(List1=innL)
> fromList(outL, "p")
[1] 0.2855202 0.6731716 0.8497825 0.7445254 0.2382722
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140414/c57159a8/attachment.html>


More information about the Rcpp-devel mailing list