Is there a R package or function that will multiple an arbitrary number of matrices supplied to it, preferably optimizing the sequence

R_function(matA, matB, matC,  matD,....)
   return matA %*%  matB %*%  matC %matD %....
  
and optimizing wether it is better to do A(BC) or (AB)C ?


Thanks,
Shiv
	[[alternative HTML version deleted]]

