简体   繁体   English

加载Rcpp并运行示例代码

[英]Loading Rcpp and Running Sample Code

I am fairly new to R and am having an issue with Rcpp. 我对R很新,我遇到了Rcpp的问题。 From this URL http://www.r-bloggers.com/installing-rcpp-on-windows-7-for-r-and-c-integration/ I have followed all steps for installing Rcpp. 从这个URL http://www.r-bloggers.com/installing-rcpp-on-windows-7-for-r-and-c-integration/我已经按照安装Rcpp的所有步骤进行了操作。 I also installed and loaded RcppClassic and Rinside. 我还安装并加载了RcppClassic和Rinside。 When I try to run the code suggested: 当我尝试运行建议的代码时:

# 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

I get the following messages: 我收到以下消息:

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’

It is also very odd that if I try to use the UI and select to load Rcpp, it does not appear as an option. 如果我尝试使用UI并选择加载Rcpp,它也不会显示为选项。

You overlooked this: 你忽略了这个:

Warning: cannot remove prior installation of package ‘Rcpp’

Stop all R sessions. 停止所有R会话。 Start a fresh one, do not load Rcpp, then try to install / upgrade it. 开始一个新的,不要加载Rcpp,然后尝试安装/升级它。

The OS you use is a little limited in that you cannot remove shared libraries that are in use. 您使用的操作系统有点受限,因为您无法删除正在使用的共享库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM