Spin-lattice coupling, frustration and magnetic order in multiferroic RMnO3