【发布时间】:2016-04-05 21:47:56
【问题描述】:
首先我知道这可能是一个 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"
注意,我的 NameSpace 有 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 ....
这里的 cmets 被正确创建并导出到 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 是两个系统之间的中介。
【问题讨论】: