如何在R包中加载已编译的库 [英] How to load compiled library in an R package
问题描述
我正在编写一个R包,其中需要将一个已编译的库文件qserver.dll包含在内,并在将该包加载到R到整个库(myPackage)中时dym.load.该qserver.dll由第三方供应商提供,所以我没有源代码.
I am writing an R package where I need to include a compiled library file qserver.dll and dym.load it when the package is loaded in R throught library(myPackage). This qserver.dll is provided by a third party vendor so I don't have the source code.
我在互联网上做了一些研究,但是信息很少.到目前为止,我发现我应该将此文件放在包文件夹的inst/子目录中.但是,在编写程序包时如何确定该文件的路径,以便可以编写类似
I did some research on the internet but information is rare. What I have found so far is that I should put this file in the to inst/ subdirectory of my package folder. However, how I can determine the path to this file when writing the package so I can write something like
dyn.load("path/to/file/qserver.dll")
编写程序包时.非常感谢.
when writing the package. Thanks very much.
推荐答案
可通过以下方式使用包的inst
目录中的项目:
Items in the inst
directory of a package are made available through
system.file(..., package=<mypkg>)
因此,假设您在包路径<pkg>/inst/lib/qserver.dll
中包含了.dll
,则可以
so assuming you had that .dll
in a package path <pkg>/inst/lib/qserver.dll
, you can do
system.file("lib/qserver.dll", package=<mypkg>)
获取文件位置.
现在,当然,这是CRAN不能接受的,并且 CRAN储存库政策对此很清楚.因此,如果您确实需要qserver.dll
,则要么需要找到源代码,要么考虑使用其他分发途径.
Now, of course, this is not CRAN acceptable, and the CRAN Repository Policy is quite clear on this. So if you really need qserver.dll
, either you need to find the source code, or consider a different route for distribution.
这篇关于如何在R包中加载已编译的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!