Reputation: 3
I am trying to build an R-package (RegressionTool) by using R 4.1.0 which performs some kinds of linear regressions. In order to speed up matrix multiplications I'd like to outsource matrix multiplication operations in a .cpp script, which I would like to include in my final R package. The script Cmatmult.cpp I want to use for matrix multiplications looks as follows:
#include <RcppArmadillo.h>
#include <RcppEigen.h>
// Correctly setup the build environment
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::depends(RcppEigen)]]
using namespace Rcpp;
using namespace arma;
using namespace Eigen;
// [[Rcpp::export]]
SEXP armaMatMult(arma::mat A, arma::mat B){
arma::mat C = A * B;
return Rcpp::wrap(C);
}
// [[Rcpp::export]]
SEXP eigenMatMult(Eigen::MatrixXd A, Eigen::MatrixXd B){
Eigen::MatrixXd C = A * B;
return Rcpp::wrap(C);
}
// [[Rcpp::export]]
SEXP eigenMapMatMult(const Eigen::Map<Eigen::MatrixXd> A, Eigen::Map<Eigen::MatrixXd> B){
Eigen::MatrixXd C = A * B;
return Rcpp::wrap(C);
}
In the RegressionTool folder, besides the folder R containing the R6 classes, the files DESCRIPTION and NAMESPACE, I saved the folder src containing the file Cmatmult.cpp. In order to try to compile the package, I run the following commands in the R console:
RcppArmadillo::RcppArmadillo.package.skeleton("RegressionTool")
Rcpp::compileAttributes()
roxygen2::roxygenize(roclets="rd")
I noticed that the RcppArmadillo.package.skeleton()
command, which generates a subfolder RegressionTool, does not generate any Makevars/Makevars.win file. While the first two commands run without errors, the last command stops with the following error:
C:/Program Files/R/R-4.1.0/library/RcppArmadillo/include/armadillo_bits/translate_blas.hpp:88: undefined reference to `dsyrk_'
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'RegressionTool'
I already included in the DESCRIPTION file stored in the folder RegressionTool the LinkingTo:
and Depends:
for Rcpp and RcppArmadillo, but I still do not understand why the Makevars/Makevars.win files are not generated (and whether this is the reason why roxygenize
runs into error).
Upvotes: 0
Views: 152
Reputation: 368489
You claim that the package skeleton generator for RcppArmadillo would not create src/Makevars{,.win}
. I cannot reproduce that:
edd@rob:~$ cd /tmp/
edd@rob:/tmp$ rm -rf RegressionTool # just in case
edd@rob:/tmp$ Rscript -e 'RcppArmadillo::RcppArmadillo.package.skeleton("RegressionTool")'
Calling kitten to create basic package.
Creating directories ...
Creating DESCRIPTION ...
Creating NAMESPACE ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './RegressionTool/Read-and-delete-me'.
Adding pkgKitten overrides.
>> added .gitignore file
>> added .Rbuildignore file
>> added tinytest support
First time using roxygen2. Upgrading automatically...
Updating roxygen version in /tmp/RegressionTool/DESCRIPTION
ℹ Loading RegressionTool
Warning: The existing 'NAMESPACE' file was not generated by roxygen2, and will not be overwritten.
Writing hello2.Rd
Deleted 'Read-and-delete-me'.
Done.
Consider reading the documentation for all the packaging details.
A good start is the 'Writing R Extensions' manual.
And run 'R CMD check'. Run it frequently. And think of those kittens.
Adding RcppArmadillo settings
>> added Imports: Rcpp
>> added LinkingTo: Rcpp, RcppArmadillo
>> added useDynLib and importFrom directives to NAMESPACE
>> added Makevars file with Rcpp settings
>> added Makevars.win file with RcppArmadillo settings
>> added example src file using armadillo classes
>> added example Rd file for using armadillo classes
>> invoked Rcpp::compileAttributes to create wrappers
edd@rob:/tmp$
This has without error and does create the files:
edd@rob:/tmp$ ls -l RegressionTool/src/
total 16
-rw-rw-r-- 1 edd edd 597 Jun 30 07:07 Makevars
-rw-rw-r-- 1 edd edd 597 Jun 30 07:07 Makevars.win
-rw-rw-r-- 1 edd edd 1453 Jun 30 07:07 rcpparma_hello_world.cpp
-rw-rw-r-- 1 edd edd 2490 Jun 30 07:07 RcppExports.cpp
edd@rob:/tmp$
There is also a unit test for package creation, and the package has been in good standing at CRAN for many years. All of which makes me suspect something is different at your end.
PS I also just checked in a Docker container without package pkgKitten
present, just in case, and it passes the same way.
Upvotes: 0