<div dir="ltr"><div><div><div><div>I will send the complete code and bold the part where it get stuck.<br><br>C++ code template created :<br><br>namespace Rcpp{<br>  template<> te::da::DataSourceInfo as (SEXP datasource){<br> <b> Rcpp::List dataSource (datasource);</b><br>  te::da::DataSourceInfo ds;<br>  Rcpp::String typestring = (dataSource["type"]);<br>  std::string tstring = typestring;<br>  if(tstring == "OGR"){<br><br>    std::map<std::string, std::string> connInfo;<br>    Rcpp::List cInfo = dataSource["connInfo"] ;<br>    connInfo.insert(std::pair<std::string,Rcpp::String>("URI",cInfo["URI"]));<br>    ds.setConnInfo(connInfo);<br>    ds.setType("OGR");<br><br>     }<br></div>   return ds<br>  }<br>}<br><br><br></div>Here is where I try to use the template<br><br>SEXP getTrajectory(SEXP datasource, SEXP dataset){<br> try<br>  {<br>    //Indicates the data source<br>    te::da::DataSourceInfo dsinfo = Rcpp::as<te::da::DataSourceInfo>(datasource);<br>   [.....]<br>   }<br>}<br><br><br></div>Here is the R list I send in the "datasource" <br>$connInfo<br>[1] "con"<br><br>$title<br>[1] "titl"<br><br>$accessDriver<br>[1] "ad"<br><br>$title<br>[1] "typ"<br><br><br></div>I send using this method :<br><br>setMethod(<br>  f = "getTrajectory",<br>  signature = c("DataSourceInfo","DataSetInfo"),<br>  definition = function(datasource, dataset)<br>  {<br>    loadPackages()<br>    dsource <- list("connInfo"=datasource@connInfo,"title"=datasource@title,"accessDriver"=datasource@accessDriver,"title"=datasource@type)<br>    print(dsource)<br><br>    dset <- list("tableName"=dataset@tableName)<br>    c(dset,"phTimeName"=dataset@phTimeName)<br>    c(dset,"geomName"=dataset@geomName)<br>    c(dset,"trajId"=dataset@trajId)<br>    c(dset,"trajName"=dataset@trajName)<br>    c(dset,"objId"=dataset@trajName)<br><br>    traj1 <- getTrajectory(datasource,dataset)<br>    return (traj1)<br>  }<br>)<br><div><div><br><br></div><div>Is this enough and understandable ?<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-17 20:58 GMT-02:00 Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On 17 February 2016 at 20:28, Diego Monteiro wrote:<br>
| Hello, I'm trying to implement a conversion from a R type into my own Type ,<br>
| but  in the beginning I am getting an error.<br>
|<br>
| The code is like the following :<br>
| template<> MyType as (SEXP x){<br>
|<br>
|   Rcpp::List dataSource(x);<br>
| [.....]<br>
| }<br>
|<br>
| This is the ERROR:<br>
| An exception has occurried: could not convert using R function : as.list<br>
|<br>
| "x"  is a char list.<br>
|<br>
| Thanks for any help.<br>
<br>
</div></div>Can you distill things to a minimal working example?  It is pretty hard for<br>
us to say something meaningful otherwise.<br>
<span class="HOEnZb"><font color="#888888"><br>
Dirk<br>
<br>
--<br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</font></span></blockquote></div><br></div>