[Rcpp-devel] Selecting rows and columns of matrices
Dirk Eddelbuettel
edd at debian.org
Wed May 18 18:07:29 CEST 2011
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
More information about the Rcpp-devel
mailing list