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

编程入门 行业动态 更新时间:2024-10-27 11:22:50
本文介绍了如何在R包命名空间文件中正确使用useDynLib()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尽管互联网上存在一些解决方案,但我发现这些解决方案都不适合我当前面临的问题(尽管也许我只是太笨了):

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

我正在尝试构建一个R包,该包广泛使用Makefile编译的共享对象(是的,我知道这是一种不好的做法,但是不能告诉Makevars文件将C和Fortran代码编译为一个共享对象)来自程序包src目录中的代码.无论我在哪里将.so编译到(我尝试过src,libs和程序包基本文件夹)或如何命名(如上述解决方案之一所述,都必须像其所包含的程序包一样进行命名) ,R CMD check以

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

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

由于我的NAMESPACE文件中的useDynLib(SoMNibEN.R)指令(其中SoMNibEN.R是我的软件包的名称,但它也不能使用原始名称)

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)

我的假设是我要么错误地使用了useDynLib()命令,要么我的Makefile做错了(尽管编译效果很好,并且共享对象在我的项目文件夹中创建-我只是不这样做)不知道它是否已成功复制到软件包安装目录中.

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

所以,如果有人知道我在这里做错了什么,请告诉我!

So, if anyone knows what I might be doing wrong here, please let me know!

推荐答案

您想要包的名称作为参数,因为这是共享库的名称 >由R构建,例如useDynLib("chron").引号是可选的(例如library()等).

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"). The quotes are optional (as they are for library() etc).

我还建议不使用Makefile,而只是将C和Fortran文件拖放到src/目录中. R通常足够聪明,知道该怎么做.如果需要-I等开关,可以在此处进行设置.

I also recommend not using a Makefile, but simply dropping the C and Fortran files in the src/ directory. R is generally smart enough to know what to. If you need -I etc switches you can set them there.

最后,使用CRAN.有数百个带有已编译源代码的软件包,其中一些软件包的结构必然与您的问题相似.

Lastly, use CRAN. There are hundreds of packages with compiled sources, and some are bound to be similar in structure to your question.

更多推荐

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

本文发布于:2023-11-17 03:54:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   文件   如何在   空间   useDynLib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!