[Rcpp-devel] Template + Rcpp::List error
Diego Monteiro
dvm1607 at gmail.com
Thu Feb 18 00:22:43 CET 2016
I will send the complete code and bold the part where it get stuck.
C++ code template created :
namespace Rcpp{
template<> te::da::DataSourceInfo as (SEXP datasource){
* Rcpp::List dataSource (datasource);*
te::da::DataSourceInfo ds;
Rcpp::String typestring = (dataSource["type"]);
std::string tstring = typestring;
if(tstring == "OGR"){
std::map<std::string, std::string> connInfo;
Rcpp::List cInfo = dataSource["connInfo"] ;
connInfo.insert(std::pair<std::string,Rcpp::String>("URI",cInfo["URI"]));
ds.setConnInfo(connInfo);
ds.setType("OGR");
}
return ds
}
}
Here is where I try to use the template
SEXP getTrajectory(SEXP datasource, SEXP dataset){
try
{
//Indicates the data source
te::da::DataSourceInfo dsinfo =
Rcpp::as<te::da::DataSourceInfo>(datasource);
[.....]
}
}
Here is the R list I send in the "datasource"
$connInfo
[1] "con"
$title
[1] "titl"
$accessDriver
[1] "ad"
$title
[1] "typ"
I send using this method :
setMethod(
f = "getTrajectory",
signature = c("DataSourceInfo","DataSetInfo"),
definition = function(datasource, dataset)
{
loadPackages()
dsource <- list("connInfo"=datasource at connInfo,"title"=datasource at title
,"accessDriver"=datasource at accessDriver,"title"=datasource at type)
print(dsource)
dset <- list("tableName"=dataset at tableName)
c(dset,"phTimeName"=dataset at phTimeName)
c(dset,"geomName"=dataset at geomName)
c(dset,"trajId"=dataset at trajId)
c(dset,"trajName"=dataset at trajName)
c(dset,"objId"=dataset at trajName)
traj1 <- getTrajectory(datasource,dataset)
return (traj1)
}
)
Is this enough and understandable ?
2016-02-17 20:58 GMT-02:00 Dirk Eddelbuettel <edd at debian.org>:
>
> On 17 February 2016 at 20:28, Diego Monteiro wrote:
> | Hello, I'm trying to implement a conversion from a R type into my own
> Type ,
> | but in the beginning I am getting an error.
> |
> | The code is like the following :
> | template<> MyType as (SEXP x){
> |
> | Rcpp::List dataSource(x);
> | [.....]
> | }
> |
> | This is the ERROR:
> | An exception has occurried: could not convert using R function : as.list
> |
> | "x" is a char list.
> |
> | Thanks for any help.
>
> Can you distill things to a minimal working example? It is pretty hard for
> us to say something meaningful otherwise.
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160217/aefcbe5b/attachment.html>
More information about the Rcpp-devel
mailing list