Graphene nanoribbons are the counterpart of carbon nanotubes in graphene-based nanoelectronics. We investigate the electronic properties of chemically modified ribbons by means of density functional theory. We observe that chemical modifications of zigzag ribbons can break the spin degeneracy. This promotes the onset of a semiconducting-metal transition, or of an half-semiconducting state, with the two spin channels having a different bandgap, or of a spin-polarized half-semiconducting state -where the spins in the valence and conduction bands are oppositely polarized. Edge functionalization of armchair ribbons gives electronic states a few eV away from the Fermi level, and does not significantly affect their bandgap. N and B produce different effects, depending on the position of the substitutional site. In particular, edge substitutions at low density do not significantly alter the bandgap, while bulk substitution promotes the onset of semiconducting-metal transitions. Pyridine-like defects induce a semiconducting-metal transition.