R uses, when interfacing with other languages, the header R_ext/Complex.h
which includes the type Rcomplex
which seems to be an implementation of std::complex<double>
. The standard way of using it would be for a complex vector x_
in R
:
Rcomplex *px = COMPLEX(x_);
However, since I need to pass it to armadillo
I then do:
arma::cx_vec x(px, nrows(x_), false, false);
but armadillo
does not accept Rcomplex
types. I have tried doing instead:
std::complex<double> *px = COMPLEX(x_);
but get the following error: cannot convert ‘Rcomplex*’ to ‘std::complex<double>*’ in initialization
Do you have any clue for passing a complex vector in R to std::complex<double> type
? I am aware of Rcpp
but would like to have a direct solution relying on base R.
EDIT: Following one of the comments, I wanted to clarify that Rcomplex
is of C
type but that it is compatible with std::complex<double>
according to the answer by @Stephen Canon.
EDIT2: Why does Dirk's answer have more votes than the accepted answer if it is not answering the "without dependencies" question. In addition, I have been downvoted apparently because if one wants preferably to use base R with C or C++ somebody does not like it. Anyway, I have better things to do but this is not the first time that I get no answer to my original question when asking something related to base R interfacing with C or C++ and get a Rcpp
related answer that I have not asked for.