How to build a R package with both RcppArmadillo and RcppParallel

Hi All,

RStudio offers a fantastic feature to help users build R package via "New Project -- New Directory". I have used it a lot to build R package with or without RcppArmadillo. But recently, I would like to build an R package with both RcppArmadillo and RcppParallel. I tried to added something on the basis of the "RcppArmadillo supporting" package to support RcppParallel but failed. Another option is to start from "RcppParallel supporting" package but also did not work. Could any one provide a link or an example to help me out? Thanks a lot in advance!

(Following Hong's code, I first create an R package via "New Project -- New Directory -- R Package using RcppParallel", and then add #include <RcppArmadillo.h> in .cpp file and add LinkingTo: Rcpp, RcppParallel, RcppArmadillo to DESCRIPTION)

Thanks,
Wenjian

My SAR package (also on CRAN) uses both RcppArmadillo and RcppParallel. You could check it out and see if its structure helps you any.

1 Like

Hi Hong,

Thanks a lot for the swift reply! You give a good start point to figure out the problem. When installing package, some functions work well, such as arma::mean. And some operator also works well, such as Mat + Mat.

But when I tried Mat * Mat, it outputs error " arma.o:arma.cpp:(.text+0x14bb): undefined reference to `dgemv_' "

And when I tried Mat % Mat, it outputs a similar error information.

Do you by any chance know how to solve this? BTW, when I used sourceCpp(), it works well.

(Update: try first create an R package with RcppArmadillo and then add something to import RcppParallel, and then it works)

Thanks,
Wenjian