[Rcpp-devel] Rcpp::List lost attributes after updating elements

Jiqiang Guo guojq28 at gmail.com
Sun Dec 9 20:07:45 CET 2012


Hi,

For a Rcpp::List object, the attributes got lost say if I add another
element to the list.  I am not sure this is supposed to be, but it's not in
R.  The following is some code to demonstrate that.

> library(Rcpp)
> src <- '
+ #include <Rcpp.h>
+ // [[Rcpp::export]]
+ SEXP crtlist() {
+   Rcpp::List lst;
+   lst["e1"] = 10;
+   lst.attr("att1") = 1;
+   return lst;
+ }
+ '
> sourceCpp(code = src)
> crtlist();
$e1
[1] 10

attr(,"att1")
[1] 1
>
> src2 <- '
+ #include <Rcpp.h>
+ // [[Rcpp::export]]
+ SEXP crtlist2() {
+   Rcpp::List lst;
+   lst["e1"] = 10;
+   lst.attr("att1") = 1;
+   lst["e2"] = 20;
+   return lst;
+ }
+ '
> sourceCpp(code = src2)
> crtlist2();
$e1
[1] 10

$e2
[1] 20

>

Note in the above, the printout for the second does not print any attribute
as for the first function.

--
Jiqiang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121209/b7f79f98/attachment.html>


More information about the Rcpp-devel mailing list