parameters: (fname, out, matrix, n=-1)
docstring: Convert a RData file to binary format.
      :param fname: path to the RData file
      :param out: path to the output file
      :param matrix: name of the matrix being converted in the RData
      :param n: write only the first n rows, or -1 for all rows
docstring_summary: Convert a RData file to binary format.
      :param fname: path to the RData file
      :param out: path to the output file
      :param matrix: name of the matrix being converted in the RData
      :param n: write only the first n rows, or -1 for all rows
docstring_tokens: Convert a RData file to binary format . : param fname : path to the RData file : param out : path to the output file : param matrix : name of the matrix being converted in the RData : param n : write only the first n rows or - 1 for all rows
function: def rdata_to_binary(fname, out, matrix, n=-1):
      """
      Convert a RData file to binary format.
      :param fname: path to the RData file
      :param out: path to the output file
      :param matrix: name of the matrix being converted in the RData
      :param n: write only the first n rows, or -1 for all rows
      """
      import rpy2.robjects as robjects
      import rpy2.robjects.numpy2ri
  
      robjects.r['load'](fname)
      data = robjects.numpy2ri.ri2py(robjects.r[matrix][0])
  
      with open(out, 'wb') as outfile:
          for i, row in enumerate(data):
              if i == n: break
              _write_floats(row.astype(np.float32), outfile)
function_tokens: def rdata_to_binary ( fname , out , matrix , n = - 1 ) : import rpy2 . robjects as robjects import rpy2 . robjects . numpy2ri robjects . r [ 'load' ] ( fname ) data = robjects . numpy2ri . ri2py ( robjects . r [ matrix ] [ 0 ] ) with open ( out , 'wb' ) as outfile : for i , row in enumerate ( data ) : if i == n : break _write_floats ( row . astype ( np . float32 ) , outfile )