Competing Electronic and Structural Effects In The Metal-Insulator Transition of Bulk and Layer-Confined RNiO$_3$