Hi, I am not sure what I am missing. Any help would be greatly appreciated. I have the following code: // myList will have column called "a" Rcpp::List myList = someInputList; Rcpp::NumericVector test = Rcpp::as<Rcpp::NumericVector>(myList["a"]); /* up to the above line, everything compiles. Now I want to get a double out from first element of test.*/ double test0 = Rcpp::as<double>(test[0]); It is the above line that the compiler complains about. I have include Rcpp.h and also my -I path includes Rcpp/include directory. I am not sure why I am getting an error here? Or I have to make a copy of SEXP object representing test[0] before passing it into Rcpp::as<double>? Thank you. Best regards, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121205/f1a0b120/attachment.html>
[Rcpp-devel] "No matching function for call to as(double&)" error at compile time
3 messages · Robert A'gata, Dirk Eddelbuettel, Romain Francois
On 5 December 2012 at 23:57, Robert A'gata wrote:
| Hi, | | I am not sure what I am missing. Any help would be greatly appreciated. I have | the following code: | | // myList will have column called "a" | Rcpp::List myList = someInputList; | Rcpp::NumericVector test = Rcpp::as<Rcpp::NumericVector>(myList["a"]); | | /* up to the above line, everything compiles.? | Now I want to get a double out from first element of test.*/ | | double test0 = Rcpp::as<double>(test[0]); Try double test= test[0]; Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Le 06/12/12 05:57, Robert A'gata a ?crit :
Hi, I am not sure what I am missing. Any help would be greatly appreciated. I have the following code: // myList will have column called "a" Rcpp::List myList = someInputList; Rcpp::NumericVector test = Rcpp::as<Rcpp::NumericVector>(myList["a"]); /* up to the above line, everything compiles. Now I want to get a double out from first element of test.*/ double test0 = Rcpp::as<double>(test[0]); It is the above line that the compiler complains about. I have include Rcpp.h and also my -I path includes Rcpp/include directory. I am not sure why I am getting an error here? Or I have to make a copy of SEXP object representing test[0] before passing it into Rcpp::as<double>? Thank you. Best regards, Robert
Of course you get a compile error. I'm sure it was explicit enough. I get :
foo.cpp:7: error: no matching function for call to ?as(double&)?
which should give you enough of a clue.
The argument for as is a SEXP :
template <typename T> T as( SEXP m_sexp)
and NumericVector::operator[](int) gives you a reference to a double
Romain
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 R Graph Gallery: http://gallery.r-enthusiasts.com blog: http://romainfrancois.blog.free.fr |- http://bit.ly/RE6sYH : OOP with Rcpp modules `- http://bit.ly/Thw7IK : Rcpp modules more flexible