[R-pkg-devel] Problem (with complex.h?) under Microsoft Windows

Dirk Eddelbuettel edd at debian.org
Sat Nov 14 05:02:01 CET 2015

On 13 November 2015 at 20:24, Roebuck,Paul L wrote:
| Too bad you couldn't just use C++ std::complex, but that's a no-go if your function needs C linkage.
| <http://stackoverflow.com/questions/1063406/c99-complex-support-with-visual-studio>
| suggests MS-specific topic, but answers explain more.
| Have you looked at RCpp package?

Rcpp can help quite a bit with all of the mechanics: header files, linking,
loading, conversion, ...  We don't use it all that much for complex data
types but some things certainly work, and Baptiste has a few packages (using
RcppArmadillo) which use complex numbers.

Here is a quick example:

R> library(Rcpp)             # load Rcpp, them define a one-liner in the R shell
R> cppFunction("ComplexVector timesTwo(ComplexVector x) { ComplexVector y = x+x; return y; }")
R> timesTwo(7i)              # use it
[1] 0+14i
R> timesTwo(c(4+2i, 7i))     # vectors or scalars are the same to R
[1] 8+ 4i 0+14i

This should very much work the same way in Windows.  And note that we didn't
have to specify a single header (though you can of course should you need
extra ones -- see many examples at http://gallery.rcpp.org)


http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org

More information about the R-package-devel mailing list