Loading Rcpp and Running Sample Code

白昼怎懂夜的黑 提交于 2019-12-12 10:45:24

问题


I am fairly new to R and am having an issue with 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. I also installed and loaded RcppClassic and 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.


回答1:


You overlooked this:

Warning: cannot remove prior installation of package ‘Rcpp’

Stop all R sessions. Start a fresh one, do not load Rcpp, then try to install / upgrade it.

The OS you use is a little limited in that you cannot remove shared libraries that are in use.



来源:https://stackoverflow.com/questions/25695355/loading-rcpp-and-running-sample-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!