[Rcpp-devel] Matrix columns

Nick Sabbe nick.sabbe at ugent.be
Sat May 14 23:12:08 CEST 2011


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

 

-- Do Not Disapprove

 

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


More information about the Rcpp-devel mailing list