2013-02-18 37 views
2

我將R與這兩個程序包Rcpp和內聯一起安裝。 (我正在做一個項目,包括在R中加速一個非常緩慢的程序,並且我決定使用Rcpp)......我知道我做錯了什麼......可能錯過了一步,但我無法弄清楚。道具如果你正在閱讀這個德克!感謝Rcpp和全新的內聯軟件包pdf,但是...它仍然沒有運行。 請注意,我是一個新手。如前所述,我清理了所有其他軟件包,只有R使用Rcpp和inline安裝(當然,我也安裝了C++)。編譯代碼中的Rcpp內聯程序包錯誤

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,以及因此,如果這是一個更好的選擇認罪呃告訴。我對任何事情都很開放,最輕鬆的進展讓人欣喜若狂

回答

1

您是否確實安裝了Fortran編譯器?

如果你沒有,或者你不知道,試試你的Linux機器。 R在Windows 必須如果要使用Rcpp和內聯構建,則能夠編譯源代碼包。作爲一個快速測試方法是嘗試像

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常見問題解答中還有一些附加說明。

+0

第一段代碼完美運行,第二段代碼不完整。我得到了與帖子中所述的相同的錯誤。我正在Linux中設置R。我可以僅使用cppFunction來優化程序嗎?如果是這樣,那麼我想它會這樣做,但我認爲內聯會讓事情變得更容易 – user2082985 2013-02-18 19:27:32

+0

你有什麼版本的內聯軟件包? – 2013-02-18 19:44:41

+0

我目前在windows上使用內聯包的0.3.10版本。我切換到Linux,在那裏我安裝了最新版本的R,Rcpp和內聯包的0.3.8-1版本。我試着運行你的第一個運行良好的例子。然而,第二個給我的錯誤:錯誤:無法找到函數「rcpp」,我記得在編寫任何代碼行之前調用這兩個庫。有沒有辦法在RcppFunction中調用SEXP?如果是,那麼我認爲我會好的:) – user2082985 2013-02-22 00:09:50