[Rcpp-devel] rcpp sugar elementary question

Bharath Govindarajan bharath.quant at gmail.com
Tue Feb 19 16:58:39 CET 2013


Thanks a lot. That helped.

Regards
Bharath

On Tue, Feb 19, 2013 at 10:53 AM, Romain Francois
<romain at r-enthusiasts.com>wrote:

> _ is defined in the Rcpp namespace, so perhaps you want to add :
>
> using namespace Rcpp ;
>
> somewhere on top.
>
> Also, you could use mat.row(1) instead of mat(1,_)
>
> Romain
>
> Le 19/02/13 16:49, Bharath Govindarajan a écrit :
>
>  Hi ,
>>
>> I am trying a simple example to assign entire rows to a
>> Rcpp::NumericMatrix. I read the Rcpp sugar document and looked at a few
>> online
>> examples. My simple code below produces errors:
>>
>>
>>   #include <iostream>
>>   #include <Rcpp.h>
>>
>> using std::cout;
>> using  std:endl;
>>
>> // [[Rcpp::export]
>>
>> void test()
>> {
>>       Rcpp::NumericMatrux mat(100,100);
>>       int rows = mat.nrow();
>>       int cols  = mat.ncol();
>>       cout << "rows " << rows << endl;
>>       cout << "cols " << cols << endl;
>>        Rcpp::NumericVector row2 = mat(1,_);
>>       cout << "mat(1,_) " << row2 << endl;
>>
>>
>>
>> }
>>
>>
>> Error:   error: '_' was not declared in this scope
>>
>> Thank you
>> Bharath
>>
>
>
> --
> Romain Francois
> Professional R Enthusiast
> +33(0) 6 28 91 30 30
>
> R Graph Gallery: http://gallery.r-enthusiasts.**com<http://gallery.r-enthusiasts.com>
>
> blog:            http://romainfrancois.blog.**free.fr<http://romainfrancois.blog.free.fr>
> |- http://bit.ly/14LJhmm : bibtex 0.3-5
> `- http://bit.ly/RE6sYH  : OOP with Rcpp modules
>
> ______________________________**_________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-**project.org<Rcpp-devel at lists.r-forge.r-project.org>
> https://lists.r-forge.r-**project.org/cgi-bin/mailman/**
> listinfo/rcpp-devel<https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130219/c0b4dec0/attachment.html>


More information about the Rcpp-devel mailing list