Hi Jiqiang,
On 27 May 2012 at 21:45, Jiqiang Guo wrote:
| Dear List:
|
| I am having problem with getting Rcpp::List's element by name when
| Rcpp::List is const reference.
|
| Here is a simple demo and output. Am I not supposed to do that, but
| it is fine using index of numbers.
I think you simply cannot do 'const' --- if you remove the const qualifier
everything works just fine. Below is a shorter version of your example:
edd@max:~$ cat /tmp/jiqiang.r
library(inline)
inc <- '
void fun(Rcpp::List & lst) {
std::string s = Rcpp::as<std::string>(lst["v"]);
Rprintf(\"s=%s.\\n\", s.c_str());
}
'
src <- '
Rcpp::List l(a);
fun(l);
'
fx <- cxxfunction(signature(a = "list"), body = src,
includes = inc, plugin = "Rcpp")
fx(list(v = "hello"))
edd@max:~$ r /tmp/jiqiang.r
Loading required package: methods
s=hello.
edd@max:~$
If you want const correctness in interface, copy from our 'proxy objects'
(which reference the underlying SEXP objects from R) into proper C++ / STL
objects and move from there.
Dirk
--
Dirk Eddelbuettel | [email protected] | http://dirk.eddelbuettel.com
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel