我已经构建了自己的R包,其中包含通过inline::cfunction()
构建的c函数。在我的R项目中,我通过install.packages()
和require()
安装该软件包。当我最终调用C函数时,找不到编译的代码。
当我直接在项目中运行函数定义时,该函数是可执行的。
test = inline::cfunction(sig = c(x="integer"),
body = 'return(x);')
R CMD INSTALL --no-multiarch --with-keep.source myBayes
install.packages(pkgs = "/path/to/myPkg",
type = "source",
repos = NULL)
test(2)
test(2)
会导致:Error in .Primitive(".Call")(<pointer: 0x0>, x) :
NULL value passed as symbol address
test
会导致:An object of class "CFunc"
function (x)
.Primitive(".Call")(<pointer: 0x0>, x)
<bytecode: 0x107c0bd18>
<environment: 0x107c0fb20>
Slot "code":
[1] "#include <R.h>\n#include <Rdefines.h>\n#include <R_ext/Error.h>\n\n\nextern \"C\" {\n SEXP filee3e4c1e3f3 ( SEXP x );\n}\n\nSEXP filee3e4c1e3f3 ( SEXP x ) {\nreturn(x);\n warning(\"your C program does not return anything!\");\n return R_NilValue;\n}\n"
test
会导致:An object of class "CFunc"
function (x)
.Primitive(".Call")(<pointer: 0x101c03fa0>, x)
<environment: 0x109070418>
Slot "code":
[1] "#include <R.h>\n#include <Rdefines.h>\n#include <R_ext/Error.h>\n\n\nextern \"C\" {\n SEXP filee7277d5c2fa6 ( SEXP x );\n}\n\nSEXP filee7277d5c2fa6 ( SEXP x ) {\nreturn(x);\n warning(\"your C program does not return anything!\");\n return R_NilValue;\n}\n"
test(2)
有效,因为它成为.GlobalEnv