[Rcpp-devel] Filling a big.matrix in Rcpp

Michael Kane kaneplusplus at gmail.com
Thu Mar 14 18:18:59 CET 2013

OK, I've got it working.

You need to add the bigmemory inst directory to the PKG_CPPFLAGS, include
MatrixAccessor.hpp, and pass the pointer to the BigMatrix object to your
function. The following code should do the trick but note that it does not
create a new big.matrix object it simply modifies the big.matrix object
that is passed to your function.


  paste("-I", system.file(package="bigmemory"), "/include/bigmemory",

matFn <- '
Rcpp::XPtr<BigMatrix> bigMat(A);
MatrixAccessor<int> Am(*bigMat);

int nrows = bigMat->nrow();
int ncolumns = bigMat->ncol();
for (int j = 0; j < ncolumns; j++){
        for (int i = 1; i < nrows; i++){
                Am[j][i] = Am[j][i] + Am[j][i-1];
# same function declaration as in example 2.
funx <- cxxfunction(signature(A="externalptr"), body=matFn,   plugin =
"Rcpp", includes='#include "MatrixAccessor.hpp"')

# set up big.matrix
nrows <- 10000
bkFile <- "bigmat.bk"
descFile <- "bigmatk.desc"
bigmat <- filebacked.big.matrix(nrow=nrows, ncol=3,type="integer", init=1,
        backingfile=bkFile, backingpath=".",descriptorfile=descFile,
matDesc <- bigmemory::describe(bigmat)

funx(bigmat at address)

On Thu, Mar 14, 2013 at 12:40 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

> I do not think we have support for bigmemory's big.matrix objects. So you
> can't just assum it works.
> Contributions welcome.  This is both 'an obvious one' as it would make
> sense
> at the C++ and R levels, and something that should not be so hard as we
> support XPtr.
> Dirk
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> 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/20130314/a2b2e90b/attachment.html>

More information about the Rcpp-devel mailing list