I'm working on something that involves using both R and Mathematica. For this something, I first generate a large R list (1000 matrices, each 200x1000, mixed integer and real values) and then need to load it in Mathematica.
Exporting to text files and importing in Mathematica is not an option (a plain .txt would be about 1.6Gb in size and too time consuming to be written and read). So I tried Rlink. What I do is basically this:
- output a .RData file containing the list (roughly 55Mb, vs the 1.6Gb) from R with the
save()
command - fire up Rlink in Mathematica and
load()
the .RData file, so that it's accessible throughREvaluate[]
.
What I would like to do is to define a Mathematica object to work with directly, but doing something like
tmp = REvaluate["nameofthelist"]
leads to a memory allocation error within the Rlink R session itself. If I try with smaller subsets of the list (say 5 200x1000 matrices at once) it works, but takes forever to complete.
Any suggestion?
Here's a sample code to recreate a smaller version of the problem, set list length (here 10) to your liking/computational possibilities:
Needs["RLink`"]
InstallR[]
REvaluate["tmplist <- vector('list',10)"]
REvaluate["for (i in 1:10) tmplist[[i]] <- matrix(rnorm(200*1000),200,1000)"]
I was wondering if creating an object and then filling it by means of a loop would work (extract single columns/matrices from the list is not so computationally heavy using REvaluate[]
), but I'm no expert of Mathematica, so I'm looking for advice..
Thanks in advance!