2014-09-05 93 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,然后尝试安装/升级它。

您使用的操作系统有点有限,因为您无法删除正在使用的共享库。