Skip to content
Back to formatted view

Raw Message

Message-ID: <19919.677.648281.191879@max.nulle.part>
Date: 2011-05-14T22:31:01Z
From: Dirk Eddelbuettel
Subject: [Rcpp-devel] Accessing matrix elements
In-Reply-To: <ABDC9A72-2CCE-4134-A484-975D7C643EA6@mit.edu>

Hi Michael,

On 14 May 2011 at 18:00, Michael Braun wrote:
| Hi, Rcpp-friends:
| 
| File this post under "rookie mistake, "educational illustration," or "feature request," but I noticed something in accessing elements from Rcpp matrices that I found somewhat curious.  Consider the following code, for which the objective is just to print elements of a matrix.

Rookie mistake -- as 

|     cout << x[i,j] << "  ";  // Accessing element using square brackets

simply will not pass any C++ compiler despite whatever magic pixie Rcpp
sprinkles on top. There is no opeator[] that can take two arguments. So use
the round brackets, and rest assured that all other C++ Matrix classes I know
of do the same (e.g. Armadillo is always a good one to check.

Dirk

-- 
Gauss once played himself in a zero-sum game and won $50.
                      -- #11 at http://www.gaussfacts.com