我已经安装了R以及这两个包Rcpp和inline。(我正在做一个项目,其中包括在R中加速一个非常慢的程序,我决定使用Rcpp)。。。我知道我做错了什么。。。可能少了一步,但我想不通。如果你在读这篇文章,就给德克道具!感谢Rcpp和全新的内联包pdf,但。。。它仍然没有运行。请注意,我是个新手。如前所述,我清理了所有其他包,只有R与Rcpp和内联一起安装(当然我也安装了c++)。
library(Rcpp)
library(inline)
x<-as.numeric(1:10)
n<-as.integer(10)
code<-"
integer i
do 1 i=1, n(1)
1 x(i)=x(i)**3
"
cubefn<- cfunction(signature(n="integer",x="numeric"),code,convention=".Fortran")
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1: #include <R.h>
2:
3:
4: extern "C" {
5: void filef2424e34d61 ( int * n, double * x );
6: }
7:
8: void filef2424e34d61 ( int * n, double * x ) {
9:
10: integer i
11: do 1 i=1, n(1)
12: 1 x(i)=x(i)**3
13:
14: }
Error in compileCode(f, code, language, verbose) :
Compilation ERROR, function(s)/method(s) not created!
In addition: Warning message:
running command 'C:/R/R-2.15.2/bin/x64/R CMD SHLIB filef2424e34d61.cpp 2> filef2424e34d61.cpp.err.txt' had status 1
如果是缺少包骨架的构造:我尝试了简单的rcpp_hello_world()示例:
rcpp_hello_world <- function(){
.Call( "rcpp_hello_world", PACKAGE = "mypackage" )
}
Folder PATH listing for volume OS
Volume serial number is 769C-A616
C:.
剩下的是一长串奇怪的符号,但我能读到的是我所拥有的c++项目的名称,我没有包括它们,因为这太长了
rcpp_hello_world <-function(){
.Call("rcpp_hello_world",PACKAGE="mypackage")
}
rcpp_hello_world()
Error in .Call("rcpp_hello_world", PACKAGE = "mypackage") :
"rcpp_hello_world" not available for .Call() for package "mypackage"
任何事情都会有帮助,我也安装了linux,所以如果这是一个更好的选择,请告诉我。我现在对任何事情都持开放态度,取得的最微小进展都是令人高兴的
您真的安装了Fortran编译器吗?
如果你没有,或者你不知道,试试你的Linux盒子。如果您想使用Rcpp和内联进行构建,则Windows上的R必须能够编译源程序包。一个好的快速测试是尝试类似的东西
R> myroot <- cppFunction('double myroot(double x) { return ::sqrt(x); }')
R> myroot(16)
[1] 4
R>
或者等效地通过内联(其中rcpp
是cxxfunction(..., plugin="Rcpp")
调用的包装器,您需要最新的内联包)
R> myroot2 <- rcpp(signature(xs="numeric"),
+ body='double x=as<double>(xs); return wrap(::sqrt(x));')
R> myroot2(16)
[1] 4
R>
如果这不起作用,请阅读安装Rtools for Windows等的R基础知识。我们在Rcpp常见问题解答中也有一些额外的注意事项。