We present a canonical formulation of gravity theories whose Lagrangian is an arbitrary function of the Riemann tensor. Our approach allows a unified treatment of various subcases and an easy identification of the degrees of freedom of the theory.