[Rcpp-devel] Selecting rows and columns of matrices

Chris DuBois chris.dubois at gmail.com
Wed May 18 18:13:27 CEST 2011


Ah!  I had all the latest versions on my office computer and forgot to
update my laptop as well (which had Rcpp from 0.8.6. from 9/2010 or so).

Thanks.
Chris

On Wed, May 18, 2011 at 9:07 AM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> On 18 May 2011 at 08:42, Chris DuBois wrote:
> | Hi all,
> |
> | I've copied the following from a portion of the "Using matrices" section
> of the
> | Rcpp Quick Reference guide.  I get a compilation error that I'm having
> trouble
> | decoding.  Commenting out the third line allows it to compile, so it must
> be
> | something I've done wrong with the column selector, but I don't see it.
> |
> | Thanks in advance,
> | Chris
> |
> | PS. My g++ version is 4.5.2, in case that helps.
> |
> | src <- '
> | NumericMatrix xx(4, 5);
> | std::fill(xx.begin(), xx.end(), 8);
> | NumericMatrix::Column zzcol = xx( _, 1);
> | return(wrap(1));
> |  '
> | fun <-  cxxfunction(signature(x="numeric"), body = src, plugin="Rcpp")
> |
> | file3011595e.cpp:35:39: error: invalid conversion from ‘SEXPREC*’ to
> | ‘int’
> | file3011595e.cpp:35:39: error:   initializing argument 1 of ‘Rcpp::Matrix
> | <RTYPE>::Proxy Rcpp::Matrix<RTYPE>::operator()(int, int) [with int RTYPE
> = 14,
> | Rcpp::Matrix<RTYPE>::Proxy = double&]’
> | file3011595e.cpp:35:39: error: conversion from
> ‘Rcpp::traits::storage_type
> | <14>::type’ to non-scalar type ‘Rcpp::Matrix<14>::Column’ requested
> | make: *** [file3011595e.o] Error 1
>
> Works for me:
>
> R> src <- '
> + NumericMatrix xx(4, 5);
> + std::fill(xx.begin(), xx.end(), 8);
> + NumericMatrix::Column zzcol = xx( _, 1);
> + return(wrap(1));
> + '
> R> fun <- cxxfunction(signature(x="numeric"), body = src, plugin="Rcpp")
> R> fun(4.44)
> [1] 1
> R>
>
> Are you by chance using an ancient Rcpp version?
>
> Dirk
>
> --
> Gauss once played himself in a zero-sum game and won $50.
>                      -- #11 at http://www.gaussfacts.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110518/949bdd67/attachment-0001.htm>


More information about the Rcpp-devel mailing list