Robert was born in Stranraer in Scotland, where his father was a magistrate. He was educated at Felsted School, and his father and uncle placed him in a business in London, hoping he would become a merchant. Instead, in 1797, he purchased a commission in the 8th (The King's) Regiment of Foot. He saw much service with the regiment, in the Egyptian campaign in 1801, and as a Captain at the Battle of Copenhagen (1807) and in the Invasion of Martinique (1809).