[英]Controlling the order of useDynLib lines in NAMESPACE with roxygen2
I am working on a R package that uses an external 3rd party dll to load data. 我正在使用外部第3方dll加载数据的R包。 I have written wrapper functions to that external dll that I can call with
.C()
我已经将包装函数写入了可以用
.C()
调用的外部dll。
Assume that my package is called mypackage
and the external is called xternal.dll
. 假设我的程序包称为
mypackage
,外部程序称为xternal.dll
。 It seems that to load the mypackage.dll
that is generated during compilation it is necessary that external.dll
is loaded first. 似乎要加载在编译期间生成的
mypackage.dll
,有必要先加载external.dll
。 I am using roxygen2
to manage the NAMESPACE
file, and I have used the #' @useDynLib
tags. 我正在使用
roxygen2
来管理NAMESPACE
文件,并且使用了#' @useDynLib
标记。 Unfortunately when roxygen2
writes the NAMESPACE
file it adds the useDynLib
calls in the lexical order of the shared object being called like AZ, az. 不幸的是,当
roxygen2
写入NAMESPACE
文件时,它会按共享对象的词法顺序(如AZ,az)添加useDynLib
调用。
Is there a way to control the order of the useDynLib
in the namespace by roxygen2
? 有没有办法控制的顺序
useDynLib
在该命名空间roxygen2
?
So far I have found the follwing solutions and neither of them seems to be particularly compelling: 到目前为止,我已经找到了以下解决方案,但它们都不是特别引人注目的:
Renaming my package to be lexically ordered after the external dll. 重命名我的包以在外部dll之后按词法排序。
Managing the NAMESPACE file manually
. NAMESPACE file manually
管理NAMESPACE file manually
。
Example: The function foo.R: 示例:函数foo.R:
#' @export
#' @useDynLib xternal
#' @useDynLib mypackage
foo <- function(){
return(FALSE)
}
results in the NAMESPACE
after calling devtools::document()
: 在调用
devtools::document()
之后返回NAMESPACE
:
# Generated by roxygen2: do not edit by hand
export(foo)
useDynLib(mypackage)
useDynLib(xternal)
The package would fail to load, however if I manually swap the two useDynLib
lines the package installs and works fine. 该软件包将无法加载,但是,如果我手动交换两条
useDynLib
行,则该软件包将安装并运行良好。
After a very helpful hint received on GitHub : The solution is to use the @rawNamespace
tag, that writes a verbatim line into the NAMESPACE
file: 在GitHub上收到非常有用的提示后:解决方案是使用
@rawNamespace
标记,该标记将逐字记录行写入NAMESPACE
文件:
foo.R: foo.R:
#' @export
#' @rawNamespace useDynLib(xternal); useDynLib(mypackage)
foo <- function(){
return(FALSE)
}
results in a NAMESPACE file: 产生一个NAMESPACE文件:
# Generated by roxygen2: do not edit by hand
export(foo)
useDynLib(xternal); useDynLib(mypackage)
and the shared objects are loaded in the correct order. 并且共享对象以正确的顺序加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.