[Rcpp-devel] Inconsistent returns

Lovett, Mitch mitch.lovett at simon.rochester.edu
Tue Oct 19 20:06:06 CEST 2010

A clarification on what I wrote - the dims reported are NULL for objects
that do not report the dims correctly and then when accessing the
elements as a matrix it acts like a vector (and fails). However, both
problems only happen some of the time. Other times the correct dims are
reported and access does not fail.


From: Lovett, Mitch 
Sent: Tuesday, October 19, 2010 1:54 PM
To: 'Rcpp-devel at lists.r-forge.r-project.org'
Subject: Inconsistent returns


I am running into some strange behavior with Rcpp objects returned to R.
Specifically, I run a program that sets values on several large
matrices. I initialize these and pass the matrices back with the code
below (I don't include all the code to fill the matrix). So, I pass it
back as a list. Once in R, I summarize the list to find all the objects
of the right length. I try to get the dims on the objects and only some
of them return the correct dims some of the time, while all of them do
other times. In case it matters, these are running on MacOS and running
the previous version of Rcpp. Any help would be great.






Rcpp::NumericMatrix Res(n,nmcmc/keep);

Rcpp::NumericMatrix REs(n,nmcmc/keep);

Rcpp::NumericMatrix Rais(n,nmcmc/keep);

Rcpp::NumericMatrix Rbis(n,nmcmc/keep);

Rcpp::NumericMatrix Rthets(thet.n_rows,nmcmc/keep);

Rcpp::NumericMatrix RmovsE(n/2,mreport);


arma::mat Es(REs.begin(),n,nmcmc/keep,false);

arma::mat ais(Rais.begin(),n,nmcmc/keep,false);

arma::mat bis(Rbis.begin(),n,nmcmc/keep,false);

arma::mat es(Res.begin(),n,nmcmc/keep,false);  

arma::mat thets(Rthets.begin(),thet.n_rows,nmcmc/keep,false);

arma::colvec lls(nmcmc/keep); 

arma::mat movsE(RmovsE.begin(),n/2,mreport,false);



Rcpp::List ret=Rcpp::List::create(Rcpp::Named("lls")=Rcpp::wrap(lls),








return Rcpp::wrap(ret);




Mitchell J. Lovett

Assistant Professor of Marketing

Simon School of Business

University of Rochester

(585) 276-4020

mitch.lovett at simon.rochester.edu


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101019/a28a25d7/attachment-0001.htm>

More information about the Rcpp-devel mailing list