#NEWLINE# def create_matrix( v_list ) : #NEWLINE# #INDENT# vec_list = [ ] #NEWLINE# nrow = 0 #NEWLINE# ncol = ( - 1 ) #NEWLINE# for v_sublist in v_list : #NEWLINE# #INDENT# if ( ncol == ( - 1 ) ) : #NEWLINE# #INDENT# ncol = len ( v_sublist ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ncol != len ( v_sublist ) ) : #NEWLINE# #INDENT# raise TypeException ( 'Matrix must be rectangular' ) #NEWLINE# #UNINDENT# #UNINDENT# nrow += 1 #NEWLINE# vec_list . extend ( v_sublist ) #NEWLINE# #UNINDENT# vec = create_vector ( vec_list ) #NEWLINE# return robjects . r . matrix ( vec , nrow = nrow )