如何使用 Rcpp 注册本机例程? [英] How to register native routines with Rcpp?

查看:43
本文介绍了如何使用 Rcpp 注册本机例程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Bioconductor 包.为此,它需要通过 BiocCheck.

I am writing a Bioconductor package. In order to do that, it needs to pass BiocCheck.

我使用 Rcpp 和 Rstudio 使 C++ 代码可用于 R 使用标签 //[[Rcpp::export]] 和 Rcpp 类,而不是 SEXP 类.Rstudio 自动生成 Rcpp_export.cpp 和 Rcpp_export.R 并且它工作正常.

I am using Rcpp and Rstudio to make c++ code available to R using the tag //[[Rcpp::export]] and Rcpp classes and not SEXP ones. Rstudio generates Rcpp_export.cpp and Rcpp_export.R automatically and it works fine.

然而,BiocCheck 对此表示不满:

However, BiocCheck complains about it:

正在检查本机例程注册..

Checking native routine registration..

注册本机例程!看http://cran.r-project.org/doc/manuals/R-exts.html#Registering-native-routines

那么,有人知道如何解决这个问题吗?

So, anybody knows how to solve this?

推荐答案

我终于设法用 Rcpp 注册了本地例程并通过了 BiocCheck.我使用的是 Rcpp 0.12.9、BiocCheck 1.9.3 和 Kmisc 0.5.1.

I finally managed to register the native routines with Rcpp and passed BiocCheck. I am using Rcpp 0.12.9, BiocCheck 1.9.3 and Kmisc 0.5.1.

1) 在由 Rcpp 自动生成的文件RcppExports.cpp"中,在以下位置的每个函数前添加//[[register]]":

1) In the automatically by Rcpp generated file "RcppExports.cpp", add "// [[register]]" before each function in the following place:

// my_function
returntype my_function(...);
// [[register]]
RcppExport SEXP packagename_my_function(...) {
BEGIN_RCPP
...
END_RCPP
}

2) 然后,从 R 运行

2) Then, from R, run

Kmisc::registerFunctions(prefix="")

这将创建一个文件packagename_init.c"

This will create a file "packagename_init.c"

3) 确保你有

useDynLib(packagename, .registration=TRUE)

在您的 NAMESPACE 文件中.它也可以在没有 .registration=TRUE 的情况下工作.这应该足以通过 BiocCheck.您可以使用

in your NAMESPACE file. It also worked without the .registration=TRUE for me. This should be sufficient to pass BiocCheck. You can check the registered routines with

getDLLRegisteredRoutines("packagename")

这篇关于如何使用 Rcpp 注册本机例程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆