Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Rcpp and Running Sample Code

Tags:

c++

r

rcpp

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.

like image 781
Ron T Avatar asked Sep 05 '14 23:09

Ron T


1 Answers

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.

like image 151
Dirk Eddelbuettel Avatar answered Nov 14 '22 07:11

Dirk Eddelbuettel