2014-09-05 67 views
5

我對R相當陌生,並且遇到Rcpp問題。從這個URL http://www.r-bloggers.com/installing-rcpp-on-windows-7-for-r-and-c-integration/我已經按照安裝Rcpp的所有步驟。我還安裝並加載了RcppClassic和Rinside。當我嘗試運行代碼提示:加載Rcpp和運行示例代碼

# install packages 
install.packages(c("Rcpp", "rbenchmark", "inline", "Runit")) 

# load main two packages 
library(Rcpp) 
library(inline) 

# do something with Rcpp to quickly check that it works 
body <- ' 
NumericVector xx(x); 
return wrap(std::accumulate(xx.begin(), xx.end(), 0.0));' 

add <- cxxfunction(signature(x = "numeric"), body, plugin = "Rcpp") 

x <- 1 
y <- 2 
res <- add(c(x, y)) 
res 
#[1] 3 

我得到以下信息:

package ‘Rcpp’ successfully unpacked and MD5 sums checked 
Warning: cannot remove prior installation of package ‘Rcpp’ package 
‘rbenchmark’ successfully unpacked and MD5 sums checked package 
‘inline’ successfully unpacked and MD5 sums checked 
package ‘RUnit’ successfully unpacked and MD5 sums checked 

The downloaded binary packages are in 
     C:\Users\Ron\AppData\Local\Temp\RtmpE3jrvo\downloaded_packages 

Error in library(Rcpp) : there is no package called ‘Rcpp’ 

這也是很奇怪的是,如果我嘗試使用的用戶界面,然後選擇要加載RCPP,它不作爲選項出現。

+1

你並沒有試圖安裝pacakge *每次*你運行這個,對吧?這應該是一次性的事情。 – MrFlick 2014-09-06 00:26:07

回答

14

你忽略了這一點:

Warning: cannot remove prior installation of package ‘Rcpp’ 

停止所有的R會話。開始一個新的,不加載Rcpp,然後嘗試安裝/升級它。

您使用的操作系統有點有限,因爲您無法刪除正在使用的共享庫。