I see, thanks a lot for tracking this down. <div>In practical terms, should I change all such functions to use SEXP + explicit wrap, or will you submit a new CRAN version soon enough fixing this? Personally I don't mind waiting a bit for the CRAN fix of cda; probably noone else uses my package and I'd rather avoid making unnecessary workaround fixes. That being said, I would be surprised if no other packages broke because of this.<div>
<br></div><div>All the best,</div><div><br></div><div>baptiste</div><div><br><div><br></div><div><br><br><div class="gmail_quote">On 17 November 2012 12:44, Romain Francois <span dir="ltr"><<a href="mailto:romain@r-enthusiasts.com" target="_blank">romain@r-enthusiasts.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is about one of C++ most annoying things. order of includes.<br>
<br>
To make it short, the function that is responsible for making an R object out of the returned arma::mat is module_wrap, which calls wrap,<br>
<br>
Where module_wrap is currently written, it does not "see" the wrap() overloads from RcpppArmadillo so it just uses a version that uses begin() and end() and therefor just creates a vector.<br>
<br>
So, alright. I broke this. This is an easy fix, although I'm afraid one that has to happen in Rcpp.<br>
<br>
A contingency measure might be to write your euler function like this:<br>
<br>
<br>
<br>
SEXP euler(const double phi, const double theta, const double psi)<br>
  {<br>
    arma::mat Rot(3,3);<br>
    const double cosphi = cos(phi), cospsi = cos(psi), costheta = cos(theta);<br>
    const double sinphi = sin(phi), sinpsi = sin(psi), sintheta = sin(theta);<br>
    Rot(0,0) = cospsi*cosphi - costheta*sinphi*sinpsi;<br>
    Rot(0,1) = cospsi*sinphi + costheta*cosphi*sinpsi;<br>
    Rot(0,2) = sinpsi*sintheta;<br>
<br>
    Rot(1,0) = -sinpsi*cosphi - costheta*sinphi*cospsi;<br>
    Rot(1,1) = -sinpsi*sinphi + costheta*cosphi*cospsi;<br>
    Rot(1,2) = cospsi*sintheta;<br>
<br>
    Rot(2,0) = sinphi*sintheta;<br>
    Rot(2,1) = -cosphi*sintheta;<br>
    Rot(2,2) = costheta;<br>
<br>
    return wrap(Rot);<br>
  }<br>
<br>
because there you call the right "wrap".<br>
<br>
Of course, the desired behaviour of having arma::mat as returned type will be brought back.<br>
<br>
Romain<br>
<br>
Le 17/11/12 00:08, Dirk Eddelbuettel a écrit :<div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On 17 November 2012 at 11:31, baptiste auguie wrote:<br>
| Hi,<br>
|<br>
| (Hopefully this makes it to the list; I believe I've had problems reaching it<br>
| because of a recent change between @gmail and @googlemail).<br>
<br>
Looks like it.<br>
<br>
| I made a minimal package * to illustrate the problem of my recently broken<br>
| package cda (since yesterday's update of Rcpp). There's only one function euler<br>
| () in a Module named cda. It used to return a 3x3 matrix, but after updating to<br>
| Rcpp 0.10 it returns a vector. You can run the example with<br>
|<br>
| $ R -f inst/testing/test.r<br>
|<br>
| What am I doing wrong?<br>
|<br>
| Best,<br>
|<br>
| baptiste<br>
|<br>
| * <a href="https://dl.dropbox.com/u/352834/cda_1.2.1.tar.gz" target="_blank">https://dl.dropbox.com/u/<u></u>352834/cda_1.2.1.tar.gz</a><br>
<br>
Good example. I added one line<br>
     Rcpp::Rcout << "In Euler, Rot is " << std::endl << Rot << std::endl;<br>
and the end of 'Euler' and we see that the dimension is in fact there, but<br>
then gets lost on the way out:<br>
<br>
<br>
edd@max:/tmp/baptiste$ r -lcda -p -e'M <- cda$euler(1.1, 2.0, 3.1); dim(M); class(M); M'<br>
  [1] "cda"           "grid"          "reshape2"      "randtoolbox"<br>
  [5] "rngWELL"       "statmod"       "plyr"          "RcppArmadillo"<br>
  [9] "Rcpp"          "methods"       "base"<br>
In Euler, Rot is<br>
   -0.4378  -0.8983   0.0378<br>
   -0.3894   0.1515  -0.9085<br>
    0.8104  -0.4125  -0.4161<br>
<br>
[1] -0.43778268 -0.38941320  0.81037256 -0.89828547  0.15154235 -0.41245379<br>
[7]  0.03780919 -0.90851102 -0.41614684<br>
NULL<br>
[1] "numeric"<br>
[1] -0.43778268 -0.38941320  0.81037256 -0.89828547  0.15154235 -0.41245379<br>
[7]  0.03780919 -0.90851102 -0.41614684<br>
edd@max:/tmp/baptiste$<br>
<br>
That is with the newest Rcpp and RcppArmadillo.  So somewhere we are loosing<br>
the matrix attribute.<br>
<br>
If I 'make the whole thing slower' by explicitly converting, it works -- I<br>
just add euler2 as<br>
<br>
NumericMatrix euler2(const double phi, const double theta, const double psi) {<br>
   arma::mat M(3,3);<br>
   M = euler(phi, theta, psi);<br>
   return Rcpp::wrap(M);<br>
}<br>
// [...]<br>
function( "euler2", &euler2, "Constructs a 3x3 Euler rotation matrix" ) ;\<br>
<br>
as seen here:<br>
<br>
<br>
edd@max:/tmp/baptiste$ r -lcda -p -e'M <- cda$euler2(1.1, 2.0, 3.1); dim(M); class(M); M'<br>
  [1] "cda"           "grid"          "reshape2"      "randtoolbox"<br>
  [5] "rngWELL"       "statmod"       "plyr"          "RcppArmadillo"<br>
  [9] "Rcpp"          "methods"       "base"<br>
In Euler, Rot is<br>
   -0.4378  -0.8983   0.0378<br>
   -0.3894   0.1515  -0.9085<br>
    0.8104  -0.4125  -0.4161<br>
<br>
            [,1]       [,2]        [,3]<br>
[1,] -0.4377827 -0.8982855  0.03780919<br>
[2,] -0.3894132  0.1515423 -0.90851102<br>
[3,]  0.8103726 -0.4124538 -0.41614684<br>
[1] 3 3<br>
[1] "matrix"<br>
            [,1]       [,2]        [,3]<br>
[1,] -0.4377827 -0.8982855  0.03780919<br>
[2,] -0.3894132  0.1515423 -0.90851102<br>
[3,]  0.8103726 -0.4124538 -0.41614684<br>
edd@max:/tmp/baptiste$<br>
<br>
So somewhere between the compiler getting smarter, Conrad optimising<br>
expression and us, an attribute got lost.<br>
<br>
Maybe Romain can find a way to make this explicit.<br>
<br>
Cheers, Dirk<br>
<br>
<br>
<br>
</blockquote>
<br>
<br>
-- <br></div></div>
Romain Francois<br>
Professional R Enthusiast<br>
<a href="tel:%2B33%280%29%206%2028%2091%2030%2030" value="+33628913030" target="_blank">+33(0) 6 28 91 30 30</a><br>
<br>
R Graph Gallery: <a href="http://gallery.r-enthusiasts.com" target="_blank">http://gallery.r-enthusiasts.<u></u>com</a><br>
`- <a href="http://bit.ly/SweN1Z" target="_blank">http://bit.ly/SweN1Z</a> : SuperStorm Sandy<br>
<br>
blog:            <a href="http://romainfrancois.blog.free.fr" target="_blank">http://romainfrancois.blog.<u></u>free.fr</a><br>
|- <a href="http://bit.ly/RE6sYH" target="_blank">http://bit.ly/RE6sYH</a> : OOP with Rcpp modules<br>
`- <a href="http://bit.ly/Thw7IK" target="_blank">http://bit.ly/Thw7IK</a> : Rcpp modules more flexible<br>
<br>
</blockquote></div><br></div></div></div>