[Rcpp-devel] Why this is not working

Dirk Eddelbuettel edd at debian.org
Tue Dec 4 03:17:37 CET 2012


Honglang,

On 3 December 2012 at 19:25, Honglang Wang wrote:
| Dear All,
| Why the following code is not working:
| 
| // [[Rcpp::depends(RcppArmadillo)]]
| #include <Rcpp.h>
| #include <RcppArmadillo.h>

1) Only include RcppArmadillo.h, it will take care of Rcpp.h;
   this was just re-explained today on this list.
 
| using namespace Rcpp;
| 
| // [[Rcpp::depends(RcppArmadillo)]]
| #include <RcppArmadillo.h>

2) You don't need two includes, or depends. One will do.

| // [[Rcpp::export]]
| List test(NumericVector yr, NumericMatrix Xr) {
|   int n = Xr.nrow(), k = Xr.ncol();
|   arma::mat X(Xr.begin(), n, k, false);
|   NumericMatrix Y = arma::randu<mat>(3,3);

3) This line makes no sense,

|   arma::colvec y(yr.begin(), yr.size(), false);
|   X.each_col()+= y;
|   Y.each_col()%= y;
|   NumericMatrix Z = arma::repmat(X,4,5);

4) This line makes no sense.

|   return List::create(Named("Addition") = X,Named("Multiplication") = Y, Named
| ("Rep") =Z);
| }

Some general advice: when something complicated does not work, I generally
try to restart with something simpler, and make sure it works. 

Dirk

| 
| 
| Thanks.
| 
| Best wishes!
|  
| Honglang Wang
|  
| Office C402 Wells Hall
| Department of Statistics and Probability
| Michigan State University
| 1579 I Spartan Village, East Lansing, MI 48823
| wangho16 at msu.edu
| 
| 
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list