In a previous post, I described the two r sounds of Spanish — the trill of carro and the flap of caro — and why linguists think r is interesting. How did Spanish end up with these two different flavors of r?
The spelling of carro and caro us a strong hint: Latin had both long and short r, along with long and short versions of other consonants. The difference between Latin carrus and carus wasn’t how the r sounds were made, but how long they were held. Spanish did away with the length difference but compensated by introducing the trill/flap difference.
This is consistent with a larger pattern: except for long mm versus short m, which simply merged, Spanish found a substitute for all of Latin’s consonant length contrasts. My favorite other example is Latin’s long nn, which turned into Spanish ñ , as in año “year” (from Latin annus).
Any changes to long consonants generally also applied to short consonants at the beginning of a word. This explains why words beginning with r (like real) are trilled, even though they had a short r in Latin and are still spelled with a single r.