[SciPy-User] reading binary R data files

Andreas H. lists@hilboll...
Sat Sep 10 06:00:48 CDT 2011


> Try rpy2: http://rpy.sourceforge.net/rpy2.html

okay, I got it. Here's the code, for reference to those who read my
original question:

If the file ``datafile.dat`` contains two arrays, ``array1`` and
``array2``, which can be loaded in *R* with the ``load`` command, this
is how to read the arrays into Python::

   import numpy as np
   import rpy2

   r("load('~/datafile.dat')")

   array1 = np.array(rpy2.robjects.r["array1"])
   array2 = np.array(rpy2.robjects.r["array2"])

Thanks for your hint towards rpy2!

Cheers,
A.


More information about the SciPy-User mailing list