Reputation: 160
I have a compiled C-library (lib.dll) that I want to include in my R package so that several R functions I wrote for the package can access lib.dll's functions via .Call. I have no other C-source code in the package, and having lib.dll's source code build along with the package is not an option.
What would be the canonical way of including lib.dll in my package? Note that I'm not planning on submitting my package to CRAN, so CRAN's rules on compiled code are not that important to me, but I do want to eventually make the package available at some other online source, so always manually adding the dll after package installation would not be optimal. I feel like there is "normal" way of doing this but I can't seem to get it to work.
What I have tried sofar:
put the dll into the src folder and add the useDynLib(lib) to the NAMESPACE file, but this causes problems during building of the package
for lack of a better solution, I tried adding the dll to the already-built package, and include an .onLoad and .onAttach function (in zzz.R) that dynamically loads the dlls using library.dynam(); this seemed to work at first, and I can access lib.dll's functions directly using .Call() after loading the pakcage, but when I try accessing them via my R wrapper functions, I'm told the dll's functions are not in the namespace; I'm at a loss here, my understanding is adding the useDynLib() lines to the NAMESPACE file is meant for dll's to-be-compiled with the package
Upvotes: 1
Views: 432
Reputation: 160
In case somebody has the same question, the answer was pretty simple and given explicity in the "Writing R Extensions" manual:
"The contents of the inst subdirectory will be copied recursively to the installation directory. Subdirectories of inst should not interfere with those used by R (currently, R, data, demo, exec, libs, man, help, html and Meta, and earlier versions used latex, R-ex)." So dlls and other files can simply be put into /inst and will end up in the installed package.
Upvotes: 1