[Rcpp-devel] Matrix columns
Michael Braun
braunm at MIT.EDU
Sun May 15 00:03:50 CEST 2011
Nick:
I had a similar problem a few weeks ago. The underscore is part of the Rcpp namespace. So I added using namespace Rcpp at the beginning of my function, and then all worked well. I can't tell from the compiler output if that is *exactly* what the problem is, but it's worth taking a look.
Michael
On May 14, 2011, at 5:33 PM, <rcpp-devel-request at r-forge.wu-wien.ac.at> <rcpp-devel-request at r-forge.wu-wien.ac.at> wrote:
>
> Message: 5
> Date: Sat, 14 May 2011 23:12:08 +0200
> From: "Nick Sabbe" <nick.sabbe at ugent.be>
> Subject: [Rcpp-devel] Matrix columns
> To: <rcpp-devel at lists.r-forge.r-project.org>
> Message-ID: <02a301cc127b$95e964c0$c1bc2e40$@sabbe at ugent.be>
> Content-Type: text/plain; charset="us-ascii"
>
> Hi all,
>
>
>
> I've been trying the following, with the main part ripped from
> rcpp-quickref:
>
> SEXP dfr2Mat(SEXP dfr)
>
> {
>
> DataFrame df = dfr;
>
> int* dm = INTEGER( ::Rf_getAttrib( df, R_DimSymbol ) ) ;
>
> int rows = dm[0];
>
> int cols = dm[1];
>
> NumericMatrix retMat (rows, cols);
>
> for(int i = 0; i < cols; i++)
>
> {
>
> NumericVector curcol = df(i);
>
> //NumericMatrix::Column zzcol = xx( _, 1);
>
> NumericMatrix::Column cl = retMat.( _, i);
>
> cl = curcol;
>
> }
>
> return retMat;
>
> }
>
> When compiling this, I get some errors starting from the line after the
> comment (i.e. line 64):
>
>
>
> main.cpp: In function 'SEXPREC* dfr2Mat(SEXPREC*)':
>
> main.cpp:64: error: invalid conversion from 'SEXPREC*' to 'int'
>
> main.cpp:64: error: initializing argument 1 of 'typename
> Rcpp::Vector<RTYPE>::Proxy Rcpp::Matrix<RTYPE>::operator()(int, int) [with
> int RTYPE = 14]'
>
> main.cpp:64: error: conversion from 'double' to non-scalar type
> 'Rcpp::MatrixColumn<14>' requested
>
> main.cpp:65: error: no match for 'operator=' in 'cl = curcol'
>
> C:/Users/nisabbe/Documents/R/win-library/2.11/Rcpp/include/Rcpp/vector/Matri
> xColumn.h:40: note: candidates are: Rcpp::MatrixColumn<RTYPE>&
> Rcpp::MatrixColumn<RTYPE>::operator=(Rcpp::MatrixColumn<RTYPE>&) [with int
> RTYPE = 14]
>
>
>
> I suspect it has something to do with this underscore syntax.
>
> I compiled with the following statement:
>
> g++ -I"C:/PROGRA~1/R/R-211~1.1/include"
> -I"C:/Users/nisabbe/Documents/R/win-library/2.11/Rcpp/include" -O2 -Wall -c
> main.cpp -o main.o
>
> And the version of rcpp I installed is 0.9.4 on the most recent version of
> R.
>
>
>
> Can anyone show me what is wrong here?
>
> Besides the syntax problems, what I am doing here should work, right?
>
> I know there are non-Rcpp ways to get this done, but this is just something
> to get me started.
>
>
>
> And as an addendum: where can I find out how (not) to use this underscore?
>
>
>
> Nick Sabbe
>
> --
>
> ping: nick.sabbe at ugent.be
>
> link: <http://biomath.ugent.be/> http://biomath.ugent.be
>
> wink: A1.056, Coupure Links 653, 9000 Gent
>
> ring: 09/264.59.36
>
>
-------------------------------------------
Michael Braun
Associate Professor of Management Science (Marketing Group)
MIT Sloan School of Management
100 Main St.., E62-535
Cambridge, MA 02139
braunm at mit.edu
617-253-3436
More information about the Rcpp-devel
mailing list