<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Hello, </div><div><br></div><div>From what I understand of ArrayRCP, having read the documentation for a few minutes. (<a href="http://trilinos.sandia.gov/packages/docs/r9.0/packages/teuchos/doc/html/classTeuchos_1_1ArrayRCP.html">http://trilinos.sandia.gov/packages/docs/r9.0/packages/teuchos/doc/html/classTeuchos_1_1ArrayRCP.html</a>)</div><div>This looks like a vector and therefore it is likely that the default Exporter<T> will not be useful as it tries to use the constructor taking a SEXP : </div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">            </span>template <typename T></div><div><span class="Apple-tab-span" style="white-space:pre">          </span>class Exporter{</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>public:</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>    Exporter( SEXP x ) : t(x){}</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>    inline T get(){ return t ; }</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">          </span>private:</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>    T t ;</div><div><span class="Apple-tab-span" style="white-space:pre">          </span>} ;</div></div><div><br></div><div>you can use a RangeExporter instead which looks more compatible to what ArrayRCP looks like: </div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">                </span>template <typename T> class RangeExporter {</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>public:</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>    typedef typename T::value_type r_export_type ;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>    RangeExporter( SEXP x ) : object(x){}</div><div><span class="Apple-tab-span" style="white-space:pre">          </span>    ~RangeExporter(){}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">            </span>    T get(){</div><div><span class="Apple-tab-span" style="white-space:pre">               </span>        T vec( ::Rf_length(object) );</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>        ::Rcpp::internal::export_range( object, vec.begin() ) ;</div><div><span class="Apple-tab-span" style="white-space:pre">          </span>        return vec ;</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>    }</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">             </span>private:</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>    SEXP object ;</div><div><span class="Apple-tab-span" style="white-space:pre">          </span>} ;</div></div><div><br></div><div><br></div><div>You can probably do this by having something like this early enough (after RcppCommon.h but before Rcpp.h). </div><div><br></div><div><div>namespace Rcpp {</div><div>namespace traits {</div><div><br></div><div>  template <typename T> class Exporter<  Teuchos::ArrayRCP<T> > : public RangeExporter< Teuchos::ArrayRCP<T> >{</div><div>  public:</div><div>    Exporter( SEXP x) : RangeExporter< Teuchos::ArrayRCP<T> >(x){}  </div><div>  }</div><div><br></div><div>}</div><div>}</div></div><div><br></div><div><br></div><div>Romain</div><br><div><div>Le 23 mai 2014 à 00:42, Chaomei Lo <<a href="mailto:chaomeilo@gmail.com">chaomeilo@gmail.com</a>> a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>Sorry to confuse you, Dirk, I had my previous message title wrong.  Here below was the message with the correct title and content.</div><div> </div><div>////////////////////////////////</div><div><div>I have created R packages using Makevars and it works pretty good for me. I am able to convert from a Rcpp::NumericVector to std::vector as in below. </div>
<div> </div><div><div><em>NumericVector col_cts = buildMatrix(Xr);<br><br>vector<long unsigned int> col_counts = Rcpp::as<vector<long unsigned int>>(col_cts);<br>  </em><br>Now I am having a problem with an application involves the Trilinos library. Here below I am trying to convert a Rcpp::NumericVector to Teuchos::ArrayRCP<size_t> in the following line, it gave me errors as shown below in red.  Would you please help me with this ?</div>
<div> </div><div><em>Teuchos::ArrayRCP<size_t> col_counts=Rcpp::as<Teuchos::ArrayRCP<size_t>>(col_cts);</em></div><div> </div><div>Thanks a lot.</div><div> </div></div><div><font style="background-color:rgb(255,255,255)"><font color="#ff0000"><font>In file included from /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/as.h:25:0,<br>
  </font>                </font></font><font color="#ff0000" style="background-color:rgb(255,255,255)">from /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/RcppCommon.h:169,<br>                 from /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp.h:27,<br>
                  from buildMatrix.cpp:4:<br>/share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/internal/Exporter.h: In constructor 'Rcpp::traits::Exporter<T>::Exporter(SEXP) [with T = Teuchos::Array<br>RCP<long unsigned int>, SEXP = SEXPREC*]':<br>
 /share/apps/R/3.0.2/lib64/R/library/Rcpp/<font>include</font>/Rcpp/as.h:79:51:   instantiated from 'T Rcpp::internal::as(SEXP, Rcpp::traits::r_type_generic_tag) [with T =<br> Teuchos::ArrayRCP<long unsigned int>, SEXP = SEXPREC*]'<br>
 /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/as.h:144:84:   instantiated from 'T Rcpp::as(SEXP) [with T = Teuchos::ArrayRCP<long unsigned int>, SEXP<br> = SEXPREC*]'<br>buildMatrix.cpp:84:87:   <font>instantiated</font> from here<br>
 /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/internal/Exporter.h:31:31: error: invalid conversion from 'SEXP' to 'long int' [-fpermissive]<br>/people/d3j508/trilinos-11.6.1/trilinos-11.6.1_Install/include/Teuchos_ArrayRCP.hpp:129:1: error:   initializing argument 1 of 'Teuchos::ArrayRCP<T>::ArrayRC<br>
 P(Teuchos::ArrayRCP<T>::size_type, const T&) [with T = long unsigned int, Teuchos::ArrayRCP<T>::size_type = long int]' [-fpermissive]<br>make: *** [buildMatrix.o] Error 1<br>ERROR: compilation failed for package 'Tpkg'</font></div>
<div></div></div></div>
_______________________________________________<br>Rcpp-devel mailing list<br><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</blockquote></div><br></body></html>