简体   繁体   中英

Dynamic library not loading in R binary package build

I am trying to build a package with compiled C code in R using 'RStudio' and 'devtools' in a Windows environment.

Only one of the function uses the C code in src folder. The source package works fine. I can use all the functions. I am able to compile the C code using devtools::document() and the corresponding .dll and .o file also appears in the src folder. Then I can load the code using dev_tools::load_all or Ctrl+Shift+L and run all the functions.

However when I am building and reloading the package using Ctrl+Shift+B , I am not able to use the particular function. The function is missing from the package even thought the documentation is retained. I also get the error telling that the corresponding .dll is not loaded.

Error in library.dynam.unload(name, system.file(package = name)) : 
  DLL ‘mypackage.dll’ was not loaded

I get the same results when I am using devtools::build with binary=TRUE .

However I can find the .dll file in the library Documents\\R\\win-library\\3.0\\mypackage\\libs\\i386\\mypackage.dll . Why is this dynamic library from compiled code not being loaded?

PS: 1) devtools::has_devel() is giving TRUE 2) I am forced to use .C instead of .Call .

This is the result of the R CMD INSTALL

* installing to library 'C:/Users/lenovo/Documents/R/win-library/3.0'
* installing *source* package 'mypackage' ...
** libs
make: Nothing to be done for `all'.
installing to C:/Users/lenovo/Documents/R/win-library/3.0/mypackage/libs/i386
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (mypackage)

I was able to solve this on Windows 10 with R 3.5 by adding the following function to a file in the R/ folder.

.onUnload <- function (libpath) { library.dynam.unload("mypackage", libpath)}

Here is the reference where I found it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM