简体   繁体   English

如何在R包命名空间文件中正确使用useDynLib()

[英]How to use useDynLib() correctly in an R package namespace file

Although a few solutions exist on the internet, I found none of those suitable for the problem I'm curerntly facing (though maybe I'm simply too dumb): 虽然互联网上存在一些解决方案,但我发现这些解决方案都不适合我面临的问题(尽管我可能只是太愚蠢):

I'm trying to build an R package which makes extensive use of a shared object compiled by a Makefile (yes, bad practice, I know, but a Makevars file just can't be told to compile C and Fortran code into one shared object) from code in the package's src directory. 我正在尝试构建一个R包,它广泛使用由Makefile编译的共享对象(是的,糟糕的做法,我知道,但是不能告诉Makevars文件将C和Fortran代码编译成一个共享对象)从包的src目录中的代码。 No matter where I compile that .so to (I tried the src , libs and package base folders) or how I name it (as one of the solutions mentioned above states it must be named like the package it's contained in), R CMD check exits with 无论我在哪里编译.so(我尝试过srclibs和包基础文件夹)或者我如何命名它(作为上面提到的解决方案之一,它必须命名为包含它的包), R CMD check退出

** testing if installed package can be loaded
Error in library.dynam(lib, package, package.lib) : 
shared object ‘SoMNibEN.R.so’ not found

due to the useDynLib(SoMNibEN.R) instruction in my NAMESPACE file (where SoMNibEN.R is my package's name, but it didn't work with the original name, either) 由于我的NAMESPACE文件中的useDynLib(SoMNibEN.R)指令(其中SoMNibEN.R是我的包的名称,但它也不能用原始名称)

My assumption is that I'm either using that useDynLib() command wrong or I'm doing something wrong with my Makefile (although the compilation works pretty well and the shared object is created in my project folder - I just don't know whether it gets copied to the package installation directory successfully). 我的假设是我要么使用useDynLib()命令错误或者我的Makefile出错了(尽管编译工作得很好,共享对象是在我的项目文件夹中创建的 - 我只是不知道是否它会成功复制到包安装目录中)。

So, if anyone knows what I might be doing wrong here, please let me know! 所以,如果有人知道我在这里做错了什么,请告诉我!

You want the name of the package as the argument, as that is the name of the shared object built by R, eg useDynLib("chron") . 您希望名称作为参数,因为这是R构建的共享对象名称 ,例如useDynLib("chron") The quotes are optional (as they are for library() etc). 引号是可选的(因为它们适用于library()等)。

I also recommend not using a Makefile, but simply dropping the C and Fortran files in the src/ directory. 我还建议不要使用Makefile,只需删除src/目录中的C和Fortran文件即可。 R is generally smart enough to know what to. R通常很聪明,知道该怎么做。 If you need -I etc switches you can set them there. 如果你需要-I等开关,你可以在那里设置它们。

Lastly, use CRAN. 最后,使用CRAN。 There are hundreds of packages with compiled sources, and some are bound to be similar in structure to your question. 有数百个包含编译源的包,有些包的结构与您的问题类似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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