<font color='black' size='2' face='arial'>

<div> <font size="2">Hi all,<br>
<br>
I have decided to follow Dirk's advice and use more classical STL containers rather than Rcpp::List one.<br>
<br>
It works for me but I admit that I am still in the dark as to why the Rcpp::List way doesn't work.<br>
<br>
Thus, I consider this topic closed.<br>
<br>
Thanks.<br>
<br>
Anguel<br>
</font>
</div>



<div> <br>

</div>



<div> <br>

</div>



<div style="font-family:helvetica,arial;font-size:10pt;color:black">-----Original Message-----<br>

From: Dirk Eddelbuettel <edd@debian.org><br>

To: aakremena <aakremena@aol.com><br>

Cc: rcpp-devel <rcpp-devel@lists.r-forge.r-project.org><br>

Sent: Tue, Apr 26, 2016 1:52 pm<br>

Subject: Re: [Rcpp-devel] List of uniform_int_distribution objects<br>

<br>

<br>

On 26 April 2016 at 14:45, <a href="mailto:aakremena@aol.com">aakremena@aol.com</a> wrote:<br>

| Hi everybody,<br>

| <br>

|    1. I am trying to create an Rcpp list, each of whose elements contain an<br>

| uniform_int_distribution object.<br>

| <br>

|    2. My understanding is that since an uniform_int_distribution object is a<br>

| non-SEXP one, I need to create a specialization of wrap() first.<br>

| <br>

|    3. To this end, I am using the following (sample) piece of code:<br>

| <br>

| #include <RcppCommon.h><br>

| #include <random><br>

| namespace Rcpp {<br>

|   template <> SEXP wrap(const std::uniform_int_distribution<int> &d);<br>

| }<br>

| #include <Rcpp.h><br>

| using namespace Rcpp;<br>

| <br>

| // [[Rcpp::export]]<br>

| Rcpp::List List_of_Distributions() {<br>

|   Rcpp::List DISTR(2);<br>

|   std::uniform_int_distribution<int> dist_1(0, 5); <br>

| std::uniform_int_distribution<int> dist_2(0, 6);<br>

|   DISTR[0] = Rcpp::wrap(dist_1);  DISTR[1] = Rcpp::wrap(dist_2);<br>

| <br>

|   return DISTR;<br>

| }<br>

| <br>

| /*** R<br>

| List_of_Distributions()<br>

| */<br>

| <br>

|    4. The compilation fails with a message<br>

| <br>

| Error in dyn.load("/var/folders/12/bqytpkx93w97r3s3_h9q9k_00000gn/T//Rtmpm2tVkx<br>

| /sourcecpp_f9e75ec42b87/sourceCpp_220.so") :<br>

|   unable to load shared object '/var/folders/12/bqytpkx93w97r3s3_h9q9k_00000gn/<br>

| T//Rtmpm2tVkx/sourcecpp_f9e75ec42b87/sourceCpp_220.so':<br>

|   dlopen(/var/folders/12/bqytpkx93w97r3s3_h9q9k_00000gn/T//Rtmpm2tVkx/<br>

| sourcecpp_f9e75ec42b87/sourceCpp_220.so, 6): Symbol not found:<br>

| __ZN4Rcpp4wrapINSt3__124uniform_int_distributionIiEEEEP7SEXPRECRKT_<br>

|   Referenced from: /var/folders/12/bqytpkx93w97r3s3_h9q9k_00000gn/T//Rtmpm2tVkx<br>

| /sourcecpp_f9e75ec42b87/sourceCpp_220.so<br>

|   Expected in: flat namespace<br>

|  in /var/folders/12/bqytpkx93w97r3s3_h9q9k_00000gn/T//Rtmpm2tVkx/<br>

| sourcecpp_f9e75ec42b87/sourceCpp_220.so<br>

| <br>

|    5. I am working on OS X Mavericks and use clang-omp compiler<br>

| <br>

| Can somebody possibly direct me to what I may be doing wrong here.  Apologies<br>

| if the question seems too basic to you.<br>

<br>

We attempt to stress in our presentations that _everything_ really happens<br>

within the confines of<br>

<br>

   SEXP .Call("somefunc", SEXP a, SEXP b, SEXP c, ...)<br>

<br>

as this is the _only_ interface that R offers.<br>

<br>

We have vignettes expanding on this -- but in short you failed to convert a<br>

type only you and the compiler know to one which R and Rcpp know too.  There<br>

are means to do this.  But a faster and easier way may just be to copy into a<br>

standard STL container (std::vector<double>, say).<br>

<br>

Dirk<br>

<br>

| <br>

| Thank you in advance.<br>

| <br>

| Anguel<br>

| <br>

| <br>

| <br>

| _______________________________________________<br>

| Rcpp-devel mailing list<br>

| Rcpp-<a href="mailto:devel@lists.r">devel@lists.r</a>-forge.r-project.org<br>

| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>

<br>

-- <br>

<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>

</div>

</font>