  We study the dynamics of vortex nucleation and lattice formation in a
Bose--Einstein condensate in a rotating square optical lattice by numerical
simulations of the Gross--Pitaevskii equation. Different dynamical regimes of
vortex nucleation are found, depending on the depth and period of the optical
lattice. We make an extensive comparison with the experiments by Williams {\it
et al.} [Phys. Rev. Lett. {\bf 104}, 050404 (2010)], especially focusing on the
issues of the critical rotation frequency for the first vortex nucleation and
the vortex number as a function of rotation frequency.
