[Rcpp-devel] Using Rcpp and MATLAB MAT-File API to Read MAT Files

Elliot Joel Bernstein ejb6 at cornell.edu
Tue Mar 24 15:53:50 CET 2015


I'm trying to use the MATLAB Mat-File API to read data from MAT files into
R. (I've tried using the R.matlab package, but the matrices I'm loading can
be very large, and that method was too slow. In addition, some of the files
I'm loading are v7.3 MAT files, which are not supported by the package.) I
wrote the following simple function to start testing. It works fine if I
compile without the Rcpp parts in Visual Studio (i.e. I can call matOpen
and get a nonzero pointer), but when I run in R it crashes my R session
without displaying "Test".

#include <Rcpp.h>
#include "mat.h"

using namespace Rcpp;

// [[Rcpp::export]]
NumericVector rcpp_mat_load() {

    MATFile* mf = matOpen("z:/temp/test.mat", "r");
    printf("Test\n");
    double val = 10;
    NumericVector y = NumericVector::create(val);
    return y;
}

I am using R version 3.0.3 on Windows 7 with version 0.11.2 of Rcpp. The
input file, test.mat, is a very small MAT file that I'm just using for
testing. I am happy to provide any other details that would be helpful.

I would appreciate any suggestions for getting this to work.

Thanks!

- Elliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150324/117959a9/attachment.html>


More information about the Rcpp-devel mailing list