使用Rcpp创建模块时出错
Error creating a module with Rcpp
我正在尝试使用Rcpp开发R模块。为了它,我遵循了(Dirk Eddelbuettel的指南)
我的库的文件有如下内容:
functions.hpp:
class myclass {
// my atributes and functions
}
functions.cpp:
#include <Rcpp.h>
using namespace Rcpp;
class myclass;
RCPP_EXPOSED_CLASS(myclass)
#include "functions.hpp"
//Implementation of my funcions
RCPP_MODULE(mymodule){
class_<myclass>("myclass")
.constructor()
.method("oneMethod", &myclass::oneMethod)
//more methods
;
}
mypackageExports。R:
.onLoad<-function(libname, pkgname){
require("methods")
loadRcppModules()
}
描述:
...
LazyLoad: yes
Depends: methods, Rcpp (>= 0.12.4)
LinkingTo: Rcpp
RcppModules: mymodule
名称空间:
useDynLib(mypackage)
exportPattern("^[[:alpha:]]+")
import(Rcpp)
当我用命令R CMD INSTALL mypackage
编译库时,我有错误:
installing to /home/user/R/x86_64-pc-linux-gnu-library/3.3/mypackage/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** caught segfault ***
address (nil), cause 'memory not mapped'
Traceback:
1: .Call(Module__classes_info, xp)
2: Module(m, pkg, mustStart = TRUE)
3: doTryCatch(return(expr), name, parentenv, handler)
4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch({ mod <- Module(m, pkg, mustStart = TRUE) if (isTRUE(direct)) { populate(mod, ns) } else { forceAssignInNamespace(m, mod, ns) } assign(.moduleMetaName(m), mod, envir = ns)}, error = function(e) { stop(sprintf("failed to load module %s from package %sn%s", m, pkg, conditionMessage(e)))})
7: loadRcppModules()
8: fun(libname, pkgname)
9: doTryCatch(return(expr), name, parentenv, handler)
10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
11: tryCatchList(expr, classes, parentenv, handlers)
12: tryCatch(fun(libname, pkgname), error = identity)
13: runHook(".onLoad", env, package.lib, package)
14: loadNamespace(package, lib.loc)
15: doTryCatch(return(expr), name, parentenv, handler)
16: tryCatchOne(expr, names, parentenv, handlers[[1L]])
17: tryCatchList(expr, classes, parentenv, handlers)
18: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L msg <- conditionMessage(e) sm <- strsplit(msg, "n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "n") .Internal(seterrmessage(msg[1L])) if (!silent && identical(getOption("show.error.messages"), TRUE)) { cat(msg, file = stderr()) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
19: try({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps)})
20: library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)
21: withCallingHandlers(expr, packageStartupMessage = function(c) invokeRestart("muffleMessage"))
22: suppressPackageStartupMessages(library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE))
23: doTryCatch(return(expr), name, parentenv, handler)
24: tryCatchOne(expr, names, parentenv, handlers[[1L]])
25: tryCatchList(expr, classes, parentenv, handlers)
26: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L msg <- conditionMessage(e) sm <- strsplit(msg, "n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "n") .Internal(seterrmessage(msg[1L])) if (!silent && identical(getOption("show.error.messages"), TRUE)) { cat(msg, file = stderr()) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
27: try(suppressPackageStartupMessages(library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)))
28: tools:::.test_load_package("mypackage", "/home/user/R/x86_64-pc-linux-gnu-library/3.3")
An irrecoverable exception occurred. R is aborting now ...
Segmentation fault (core dumped)
ERROR: loading failed
谁(@DirkEddelbuettel,我的Rcpp的导师)能告诉我做错了什么吗? 你用的是2012年的指南。有时候事情会改变。我建议也查看当前使用Modules的包。
这里不再需要
.onLoad<-function(libname, pkgname){
require("methods")
loadRcppModules()
}
自2013年以来,我们所要求的只是R中的单个loadModule("moduleName", TRUE)
,实际上是任何R文件。
例如,RcppCNPy包的R/
目录的整个内容如下
edd@max:~/git/rcppcnpy(master)$ cat R/*.R
loadModule("cnpy", TRUE)
edd@max:~/git/rcppcnpy(master)$
作为包定义了一个单独的模块cnpy
。
RcppModules: ...
行。
最后,Rcpp包本身包含一个完整的工作包,其中包含用于其自己的单元测试的模块。你也可以看一下。
Edit:您可能还想在importFrom(Rcpp, evalCpp)
或NAMESPACE
上实例化Rcpp。
最后,我发现这个问题与我正在使用的依赖关系和Rcpp.h文件
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 尝试导入pybind-opencv模块时出现libgtk错误
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- TraciMobility::getExternalId 将自定义模块添加到示例中时出错Veins_Inet (Omne
- 导入 Boost Python 模块 (function_impl_base9max_arityEv) 时出错
- r-使用Rcpp模块公开带有引用参数的c++类方法时出错
- 将自定义 Apache 2.4 模块与 Linux 上的 httpd/apr 库静态链接时出错
- 重组模块后出错
- 使用Rcpp创建模块时出错