[Rcpp-devel] Accessing T of RcppVector<T>
Groß, Sebastian
sebastian.gross at stud.uni-goettingen.de
Fri Oct 29 00:34:50 CEST 2010
Hey there,
At first please forgive my intrusion into your high level development
conversation. But some, in my opinion rather weird, thing occured to me while
using the RcppVector class.
Maybe it just appears somewhat cloudy to me due to my lack of firm c++
programming experience.
To not to beat around the bush the topic is following.
I try to call a c++ function expecting a double as parameter. The parameter
is brought to the function via an R SEXP which I interprete as an
RcppVector<double>.
Obviously in case the SEXP contains just one single double value one can
access it using the operator(int i).
According to the signature of RcppVector<T>(int i) the result will be T&,
especially in my case double&.
That is exactly the point where I don't know how to proceed.
Refering to my rudimentary c knowledge, double& means the adress of a double
value so I have to access the value by using the derefering operator *, but
this does not work, I always get the gcc error: invalid argument to unary
'*'. And not using the * operator leads to the error of not matching a
candidate signature of the function I call.
In case a simplified code sample helps to understand what I intend to do:
in R
real_num <- 42.1337
tmp <- .call("func", real_num, "package=mypackage")
in C++
RcppExport SEXP func(SEXP real_num)
{
//create the vector
RcppVector<double> tmp(real_num);
//access its one and only element and call the function
other(tmp(0));
//does not work, at least not in my environment
}
void other(double any_double)
{
cout << "YAY it works" << endl;
}
I would be very thankful to any advise, information, or tip in the right
direction where to search to achieve further knowledge beyond RTFM and STFW
which I did in plenty of ways
Cheers and Thanks in advance
Sebastian
More information about the Rcpp-devel
mailing list