Rcpp编译的属性不可用于调用

Rcpp compiled Attributes not available for call

本文关键字:用于 调用 属性 编译 Rcpp      更新时间:2023-10-16

首先我知道这可能是一个Rcpp-Devel函数,但当我尝试使用Firefox或Chrome订阅时,我在工作以太网中遇到一个错误,即连接不安全,所以我现在必须在这里询问。

所以我买了德克的书,它写得很好。

我在这里遇到了类似的错误https://www.mail-archive.com/rcpp-devel%40lists.r-伪造.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"

注意,我的NameSpace有useDynLib(mySage),我可以成功地运行compileAttributes和R CMD构建(在外部目录中)并成功安装包。

当我尝试调用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名称空间这是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包,它们不包括头,那么头只用于连接API吗?

另一个可能导致此错误的原因是,我的函数参数是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从C++到R时才需要,在打包时,RcppExports.cpp是两个系统之间的中介。

这篇文章很长,很难看到结构。我建议你重新开始,做中的任何一个

  • 致电Rcpp.package.skeleton()并研究该软件包,或者
  • 使用RStudio为您创建包,或者
  • 使用类似RcppExamples的示例包

从这些开始,重建它们。然后慢慢添加您的函数,运行compileAttributes()并重建/重新安装。