首先我知道这可能是一个 Rcpp-Devel 函数,但是当我尝试使用 Firefox 或 Chrome 订阅时,我在我的工作以太网上收到一个连接不安全的错误,所以我现在必须在这里询问。
所以我购买了德克的书,它写得非常好。
我在这里遇到了类似的错误 https://www.mail-archive.com/rcpp-devel%40lists.r-forge.r-project.org/msg08059.html
Sage<-testArm(set,labels,contrast,geneSets,var.equal=FALSE)
Calculating comparisons...Error in .Call("sigmaCalc", PACKAGE = "mySage") :
"sigmaCalc" not available for .Call() for package "mySage"
请注意,我的命名空间有 useDynLib(mySage),我可以成功运行 compileAttributes 和 R CMD build(在外部目录中)并成功安装包。
当我尝试调用 RcppExport.R 函数之一时,我生成了错误
这是我的一个 Cpp 代码
//[[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
#include <algorithm>
#include <vector>
#include <Rcpp.h>
#include <math.h>
#include <R.h>
using namespace arma;
using namespace Rcpp;
//'calculates the sd and mindof in order , names are assigned in R, as of now, there is no NA error checking. not very robust
//' @param SDs standard deviations from geneResults returned by makeComparison
//' @param DOFs degrees of freedom from geneResults returned by makeComparison
//' @param geneSets a set of genes for enrichment testing
//' @export
//' @return a List with SumSigma and MinDof
//[[Rcpp::export]]
List sigmaCalc( SEXP SDs, SEXP DOFs, SEXP geneSets) {
Rcpp::NumericVector SD(SDs);
Rcpp::NumericVector DOF(DOFs);
Rcpp::List geneSet(geneSets);
more code ....
此处的注释已创建并正确导出到 R nameSpace 这是 RcppExports.R
# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#'calculates the sd and mindof in order , names are assigned in R, as of now, there is no NA error checking. not very robust
#' @param SDs standard deviations from geneResults returned by makeComparison
#' @param DOFs degrees of freedom from geneResults returned by makeComparison
#' @param geneSets a set of genes for enrichment testing
#' @export
#' @return a List with SumSigma and MinDof
sigmaCalc <- function(SDs, DOFs, geneSets) {
.Call('mySage_sigmaCalc', PACKAGE = 'mySage', SDs, DOFs, geneSets)
}
这是 RcppExport.cpp
// This file was generated by Rcpp::compileAttributes
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#include <RcppArmadillo.h>
#include <Rcpp.h>
using namespace Rcpp;
// sigmaCalc
List sigmaCalc(SEXP SDs, SEXP DOFs, SEXP geneSets);
RcppExport SEXP mySage_sigmaCalc(SEXP SDsSEXP, SEXP DOFsSEXP, SEXP geneSetsSEXP) {
BEGIN_RCPP
Rcpp::RObject __result;
Rcpp::RNGScope __rngScope;
Rcpp::traits::input_parameter< SEXP >::type SDs(SDsSEXP);
Rcpp::traits::input_parameter< SEXP >::type DOFs(DOFsSEXP);
Rcpp::traits::input_parameter< SEXP >::type geneSets(geneSetsSEXP);
__result = Rcpp::wrap(sigmaCalc(SDs, DOFs, geneSets));
return __result;
END_RCPP
}
我不确定有几件事,是否需要头文件?文本表明需要 rcpp_hello_world.h,但是在阅读 RcppExport.cpp 之后,cpp 函数声明包含在 Export.cpp 中,所以我不确定我是否需要编写声明性头文件。 networkBMA、wordcloud 和 pcaMethods 都是 Rcpp 包,它们不包含 header ,那么仅连接 API 需要 header 吗?
另一个可能导致这个错误的是我的函数参数是 SEXP 对象而不是 Rcpp:NumericVectors.../NumericMatrix ,我应该写 cpp 代码 sigmaCalc 来输入 Rcpp 类型,然后确保 Export.cpp函数处理 SEXP 转换?
谢谢。
附言这是我在 src/中的 Makevars
## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CXXFLAGS=`$(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()"`
我认为错误是我将 SEXP 作为输入输入到 cpp 函数中,这仅在将 sourceCpp 原型(prototype)设计为从 C++ 到 R 时才需要,在打包时,RcppExports.cpp 是两个系统之间的中介。
最佳答案
帖子很长,很难看清结构。我建议您重新开始并执行以下任一操作
- 调用
Rcpp.package.skeleton()
并研究该包,或者 - 使用 RStudio 为您创建一个包,或者
- 使用像RcppExamples 这样的示例包
从这些开始,重建它们。然后慢慢添加您的函数,运行 compileAttributes()
并重建/重新安装。
关于c++ - Rcpp 编译属性不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36437669/