I am calling a FORTRAN program in R and analyzing FORTRAN’s output file, which is a little big (around 50M per iteration). For each iteration, it takes about 50 seconds, in which the read.table command needs 42 seconds. Since I need to repeat this program 100,000 times, I am wondering if there are better ways to speed it up?
For example, is it possible to let FORTRAN save everything into memory and pass it to R?
Thanks!
Absolutely — write the file as binary files in Fortran, and then just read them via
readBin()in R which will be very fast. But make sure you check for endianness, four versus eight byte floating point and that.If you want a tested library, look into the various serialization libraries as eg RProtoBuf etc. Not sure how many have Fortran bindings though…
Edit: No luck with Protocol Buffers and Fortran per the add-ons page. Maybe a science-ish format like hdf5 will be better for you.