Hello Bob
James Boswell (1740-1795) the biographer and your ancestor Robert Boswell (1746-1804) the lawyer, Glasite preacher and psalm-composer, were first cousins.
Their common grandparents, James Boswell (1675-1749) and Elizabeth Bruce (1671-1739) had one daughter [Veronica, who married David Montgomerie and later became James Boswell Biographer's mother-in-law] and also two sons who survived into adulthood:
(1) Alexander Boswell (1701-1782), later Lord Auchinleck, lawyer, who married Euphemia Erskine. They had three sons: James Boswell (1740-1795) the biographer, John Boswell (1743-1790) an army officer, never married, and David Boswell (1748-1826) - aka Thomas David Boswell - a businessman
(2) John Boswell (1710-1780) a medical doctor and censor of the College Physicians, who married Anne Cramond. Their son Robert (1746-1804) was your relative.
It appears that John did have a twin brother James born in 1710, but I believe he died in infancy, as did a couple of siblings named David.
Best regards
John Humphrey