-3

This is somewhat related to the post regarding moving from sourceCpp to a package with Rcpp Moving from sourceCpp to a package w/Rcpp. However, I am using RcppArmadillo on a Mac OS X 10.10.4 and have had trouble getting a package to work. The file that works with sourceCpp is as follows:

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

using namespace Rcpp;

// [[Rcpp::export]]
arma::mat cholcalcCpp(arma::mat& SS, arma::umat& Aadj){

  int p = SS.n_rows;
  arma::mat L(p,p);
  arma::mat D(p,p);

  L = arma::eye(p,p);
  D = arma::eye(p,p);

  return (L*sqrt(D));
}

Trying to use R Studio to create a new project using Project>Create Project>Package w/Rcpp didn't work either because I kept getting an error saying that command arma wasn't recognized. I tried adding the #include <RcppArmadillo.h> in the RccpExports.cpp file, but Rstudio deletes that line every time I try to build and reload. Can anyone suggest how I can go from the .cpp file to a RccpArmadillo package? Thanks.

Community
  • 1
  • 1
  • 1
    Do you have `LinkingTo: Rcpp, RcppArmadillo` in the `DESCRIPTION` file? – nrussell Jun 24 '16 at 19:18
  • 2
    You can start from `RcppArmadillo.package.skeleton()` too. – Dirk Eddelbuettel Jun 24 '16 at 22:58
  • Thanks @Coatless and @Dirk . I have managed to get it to build and load, but now I am getting the following error when I try to call the function from R: `Error in .Primitive(".Call")(, S, adj) : NULL value passed as symbol address`. Any idea what's causing this? – Syed Rahman Jun 25 '16 at 20:54
  • I managed to fix the error `Error in .Primitive(".Call")(, S, adj) : NULL value passed as symbol address` simply by rewriting the entire package from scratch and using a different name. I'm not entirely sure why it worked though. – Syed Rahman Jun 26 '16 at 06:50

2 Answers2

1

There are a few things that could be wrong. Primarily, you do need to modify the DESCRIPTION file to include LinkingTo: Rcpp, RcppArmadillo and ensure that #include <RcppArmadillo.h> is present in each .cpp file in the /src directory. You will also need to include two Makevars files.

Makevars.win and Makevars with:

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

For a complete walkthrough of setting up RStudio to use RcppArmadillo as a package please see:

http://thecoatlessprofessor.com/programming/setting-up-rstudio-to-work-with-rcpparmadillo/

coatless
  • 20,011
  • 13
  • 69
  • 84
1

The error is basically yours in this:

Trying to use R Studio to create a new project using Project>Create Project>Package w/Rcpp didn't work either

Nobody ever said that a 'Package with Rcpp' was the same as a 'Package with RcppArmadillo'. You simply misunderstand what RStudio is kindly offering to you.

RcppArmadillo is used by well over 200 packages on CRAN. Sometimes it is just easiest to copy one of those, strip it down and start from the framework created that way. Of course, there is also an easier and documented way: Use the RcppArmadilllo.package.skeleton() function we wrote for precisely this use case: Creating a basic (working) package for RcppArmadillo.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725