[Rcpp-devel] Principal Component in Armadillo

João Daniel Nunes Duarte jdanielnd at gmail.com
Tue Mar 12 02:42:18 CET 2013


Hello,

I'm trying to calculate principal component using 'princomp' function from
RcppArmadillo. Here's the cpp code:

#include <RcppArmadillo.h>

RcppExport SEXP pca(SEXP mats) {
  try {

    Rcpp::NumericMatrix matr(mats);
    int n = matr.nrow(), k = matr.ncol();

    arma::mat mat(matr.begin(), n, k, false);
    arma::colvec pca;

    pca = arma::princomp(mat);

    return Rcpp::wrap(mat);

  } catch(...) {
    ::Rf_error("c++ error");
  }
}

However, when I "R CMD check" the package, I get the following error:

** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
'/home/tecto/cpp/Rcpp/amora.Rcheck/amora/libs/amora.so':
  /home/tecto/cpp/Rcpp/amora.Rcheck/amora/libs/amora.so: undefined symbol:
dgesvd_
Error: loading failed
Execution halted

I've read the Armadillo documentation for that function (
http://arma.sourceforge.net/docs.html#princomp), however it was not clear
to me how to use it correctly.

Does my code have any mistake?

Cheers,

João Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130311/3d351363/attachment.html>


More information about the Rcpp-devel mailing list