使用RcppArmadillo从sourceCpp迁移到软件包 [英] Moving from sourceCpp to a package with RcppArmadillo
问题描述
这与有关从sourceCpp到带有Rcpp的软件包的帖子有些相关
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));
}
尝试使用R Studio通过项目">创建项目">带有Rcpp的程序包创建新项目也没有用,因为我一直收到错误消息,说无法识别命令武器.我尝试在RccpExports.cpp文件中添加 #include< RcppArmadillo.h>
,但是每次我尝试构建和重新加载Rstudio时,Rstudio都会删除该行.谁能建议我如何从.cpp文件转到RccpArmadillo软件包?谢谢.
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.
推荐答案
有些事情可能是错误的.首先,您确实需要修改 DESCRIPTION
文件以包含 LinkingTo:Rcpp,RcppArmadillo
,并确保 #include< RcppArmadillo.h>
出现在/src
目录中的每个 .cpp
文件中.您还需要包含两个 Makevars
文件.
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
和 Makevars
具有:
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
有关设置RStudio以将RcppArmadillo作为软件包使用的完整演练,请参见:
For a complete walkthrough of setting up RStudio to use RcppArmadillo as a package please see:
http://thecoatlessprofessor.com/programming/setting-up-rstudio与rcpparmadillo一起工作/
这篇关于使用RcppArmadillo从sourceCpp迁移到软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!