<div dir="ltr">John -<div><br></div><div>Thanks for the suggestions. I tried taking not only Rcpp but R out of the loop, and just compiling from the command line with MinGW. That crashed as well, so I think there's probably a compatibility issue with MATLAB's API and MinGW. I'll contact Mathworks tech support to try and get some help with that.</div><div><br></div><div>Regarding v7.3...my files aren't all v7.3, but I could definitely save them all that way, which might be the easiest solution. I tried what you suggested with some of my real data files, which contain two variables each: a matrix and a struct. I get the following warnings:</div><div><br></div><div><div><font face="monospace, monospace">> data <- h5dump("z:/temp/test73.mat", bit64conversion='double')</font></div><div><font face="monospace, monospace">Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced by NA's</font></div><div><font face="monospace, monospace">Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced by NA's</font></div><div><font face="monospace, monospace">Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced by NA's</font></div></div><div><font face="monospace, monospace"><br></font></div>The data look OK, as far as I can tell. (The matrix is 411x30927, so it's not like I can check every element, but I don't see anything obviously wrong.) In addition to the two variables I was expecting, the result has two additional elements, #refs# and #subsystem. I'm not actually sure how to see what they contain, since the names include the comment character. Can I safely ignore those warnings?<div><br>Thanks.<br><br>- Elliot<div><font face="monospace, monospace"><br></font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 25, 2015 at 11:09 AM, John Buonagurio <span dir="ltr"><<a href="mailto:jbuonagurio@exponent.com" target="_blank">jbuonagurio@exponent.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Elliot,<br>
<br>
How are you building the executable? Did you make sure to include all dependencies in the search path (run depends.exe against libmat.dll and libmx.dll)? Did you make sure to set the appropriate architecture e.g. -m64 in CFLAGS? I don't have access to the MAT-File libraries to test this myself.<br>
<br>
Start simple and take Rcpp out of the equation. Call matOpen from a simple C function with type void. Does it work with dyn.load() and .C()?<br>
<br>
If you are *only* working with v7.3 files which are based on HDF5, you may be able to avoid this issue and access them using rhdf5:<br>
<br>
source("<a href="http://bioconductor.org/biocLite.R" target="_blank">http://bioconductor.org/biocLite.R</a>")<br>
biocLite("rhdf5")<br>
library(rhdf5)<br>
h5dump("file.mat", load=FALSE)<br>
<br>
John<br>
<br>
From: <a href="mailto:rcpp-devel-bounces@lists.r-forge.r-project.org">rcpp-devel-bounces@lists.r-forge.r-project.org</a> [mailto:<a href="mailto:rcpp-devel-bounces@lists.r-forge.r-project.org">rcpp-devel-bounces@lists.r-forge.r-project.org</a>] On Behalf Of Elliot Joel Bernstein<br>
<span class="">Sent: Wednesday, March 25, 2015 9:28 AM<br>
To: Dale Smith<br>
Cc: <a href="mailto:xian@unm.edu">xian@unm.edu</a>; <a href="mailto:rcpp-devel@lists.r-forge.r-project.org">rcpp-devel@lists.r-forge.r-project.org</a><br>
</span>Subject: Re: [Rcpp-devel] R.e. Using Rcpp and MATLAB MAT-File API to Read MAT Files<br>
<div class="HOEnZb"><div class="h5"><br>
Dale -<br>
<br>
Thank you for the suggestion. I have MATLAB and the MATLAB libraries, and I am not looking to redistribute anything. I just have a lot of data in MAT files that I would like to be able to load analyze in R. I am able to compile and link against the MATLAB libraries, but the code crashes when I run it. I looked into the Octave FAQ. It looks like they don't handle v7.3 files either, and I don't think they provide an API that I could access from R/C++.<br>
<br>
- Elliot<br>
<br>
On Wed, Mar 25, 2015 at 8:36 AM, Dale Smith <<a href="mailto:DSmith@nexidia.com">DSmith@nexidia.com</a>> wrote:<br>
mat.h is a header file which comes with MATLAB. I don't think the license allows redistribution, and you would not be able to compile without the MATLAB libraries.<br>
<br>
An alternative may be Octave since it will read .mat files. Perhaps someone can email the name of the header file used from the Octave distribution?<br>
<br>
<a href="http://stackoverflow.com/questions/9915658/how-do-you-open-mat-files-in-octave" target="_blank">http://stackoverflow.com/questions/9915658/how-do-you-open-mat-files-in-octave</a><br>
<br>
This also offers a viable way to test this type of code for those who don't have MATLAB.<br>
<br>
Dale Smith, Ph.D. | Data Scientist | nexidia | office: <a href="tel:%2B1%20404%20495%207220%20ext%204008" value="+14044957220">+1 404 495 7220 ext 4008</a> | fax: <a href="tel:%2B1%20404%20495%207221" value="+14044957221">+1 404 495 7221</a> | <a href="http://nexidia.com" target="_blank">nexidia.com</a><br>
<br>
<br>
-----Original Message-----<br>
From: <a href="mailto:rcpp-devel-bounces@lists.r-forge.r-project.org">rcpp-devel-bounces@lists.r-forge.r-project.org</a> [mailto:<a href="mailto:rcpp-devel-bounces@lists.r-forge.r-project.org">rcpp-devel-bounces@lists.r-forge.r-project.org</a>] On Behalf Of Christian Gunning<br>
Sent: Wednesday, March 25, 2015 8:08 AM<br>
To: <a href="mailto:rcpp-devel@lists.r-forge.r-project.org">rcpp-devel@lists.r-forge.r-project.org</a><br>
Subject: [Rcpp-devel] R.e. Using Rcpp and MATLAB MAT-File API to Read MAT Files<br>
<br>
Can you provide a link to the mat.h file referenced in the source (which I assume is the same as the API mentioned below)?<br>
<br>
Also, see Dirk's comments about compilers here:<br>
<a href="http://stackoverflow.com/questions/10723165/using-visual-c-with-r" target="_blank">http://stackoverflow.com/questions/10723165/using-visual-c-with-r</a><br>
and here:<br>
<a href="http://dirk.eddelbuettel.com/code/rcpp/Rcpp-FAQ.pdf" target="_blank">dirk.eddelbuettel.com/code/rcpp/Rcpp-FAQ.pdf</a><br>
<br>
Best,<br>
Christian<br>
<br>
> I'm trying to use the MATLAB Mat-File API to read data from MAT files<br>
> into R. (I've tried using the R.matlab package, but the matrices I'm<br>
> loading can be very large, and that method was too slow. In addition,<br>
> some of the files I'm loading are v7.3 MAT files, which are not<br>
> supported by the package.) I wrote the following simple function to<br>
> start testing. It works fine if I compile without the Rcpp parts in<br>
> Visual Studio (i.e. I can call matOpen and get a nonzero pointer), but<br>
> when I run in R it crashes my R session without displaying "Test".<br>
><br>
> #include <Rcpp.h><br>
> #include "mat.h"<br>
><br>
> using namespace Rcpp;<br>
><br>
> // [[Rcpp::export]]<br>
> NumericVector rcpp_mat_load() {<br>
><br>
>     MATFile* mf = matOpen("z:/temp/test.mat", "r");<br>
>     printf("Test\n");<br>
>     double val = 10;<br>
>     NumericVector y = NumericVector::create(val);<br>
>     return y;<br>
> }<br>
<br>
--<br>
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<br>
</div></div></blockquote></div><br></div>