How to load compiled library in an R package

瘦欲@ 提交于 2019-12-11 23:33:46

问题


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.

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.


回答1:


Items in the inst directory of a package are made available through

system.file(..., package=<mypkg>)

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>)

to get the file location.

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.



来源:https://stackoverflow.com/questions/21715127/how-to-load-compiled-library-in-an-r-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!