5

I am trying to figure out an error that stopped me from making an R package "whyNotWork" using RcppArmadillo. The package contains only one .cpp file with one simple function which returns the eigen values of a matrix:

// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>

// [[Rcpp::export]]
arma::vec getEigenValues(arma::mat M) 
{
    return arma::eig_sym(M);
}

In the DESCRIPTION file I added:

Imports:
    Rcpp (>= 0.12.1), RcppArmadillo
LinkingTo:
    Rcpp, RcppArmadillo
Depends: RcppArmadillo

In the NAMESPACE file I added:

exportPattern("^[[:alpha:]]+")
useDynLib(whyNotWork)
import(RcppArmadillo)
importFrom(Rcpp, evalCpp)

That function works fine if I was not trying to make a package--the "source" button will successfully load the function and it works correctly. However, when making the package, hitting the "Build & Reload" button will give the following error:

arma.o:arma.cpp(.text$_ZN4arma6auxlib7eig_symIdNS_3MatIdEEEEbRNS_3ColIT_EERKNS_4BaseIS5_T0_EE[_ZN4arma6auxlib7eig_symIdNS_3MatIdEEEEbRNS_3ColIT_EERKNS_4BaseIS5_T0_EE]+0x28d): undefined reference to `dsyev_'

I googled "dsyev" and it seems to be related to LAPCAK..


A solution:

New a .txt file in the src folder. Add

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

in the file.

Rename the txt file as Makevars.win (if it's not Windows system, no .win). Package is successfully made.

The solution is found by comparing the files generated from RcppArmadillo.package.skeleton() and those from Rstudio

1
  • For the record, that 'solution' is both clearly documented and recommended. It even gets done by our tools. This was a simple user error, and such the question was closed. Commented Dec 10, 2015 at 13:46

1 Answer 1

5

What is your OS?

What does R CMD config LAPACK_LIBS return?

Did you build R yourself or did you download a binary?

On most systems (Linux, OS X, ...) R will use external LAPACK libraries. On Windows it may uses its own (reduced) copy of LAPACK which is lacking some functionality.

For what it is worth, your program builds just fine on my system with external LAPACK libraries:

R> sourceCpp("/tmp/arma_sym.cpp")
R> v <- 1:4; getEigenValues(v %*% t(v))  
             [,1]
[1,] -2.33587e-15
[2,]  0.00000e+00
[3,]  2.33587e-15
[4,]  3.00000e+01
R> 
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks Dirk! sorry to mention that I am using Windows. I just found a way to solve it by comparing the files generated from your RcppArmadillo.package.skeleton() and those from Rstudio. The package is successfully built by adding the "Makevars.win" file in the src folder
Let's delete the question then. Your package was just built wrong.
OK, so under Windows, with Rstudio is there any way other than "adding a Makervars.win" file to build a RcppArmadillo package?
You are supposed to know what you are doing, or use RcppArmadillo.package.skeleton().
I don't see why this merits deletion of the question; I found this problem through google and it helped me solve my problem. So I guess the question must have some value...I've used RcppArmadillo before with the RcppArmadillo.package.skeleton(), but when using RStudio on a new project it also creates a skeleton with Rcpp projects, and I didn't think to change anything to use Armadillo.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.