Electronic-structure evolution through the metal-insulator transition in RNiO3