Brought up in Dalkeith, McWilliam became a licentiate of the Edinburgh College of Surgeons in 1827, and entered the Royal Navy in 1829 as assistant-surgeon. After serving abroad in this capacity for seven years, he was appointed surgeon to 'HMS Scout on the west coast of Africa. McWilliam returned to England in November 1839, and attended the London medical schools and hospitals. He became M.D. of Edinburgh in 1840, and in September of the same year was appointed senior surgeon on board the steamer Albert, which joined the expedition sent to the River Niger for geographical and commercial purposes, and against the continuing Atlantic slave trade. The Albert and two other vessels left England on 12 May 1841, and entered the Niger on 18 August. On 4 September a malignant fever broke out in the Albert, and almost simultaneously in the other two vessels. The latter were sent back to sea filled with the sick and dying, leaving the Albert to continue the voyage alone. By 4 October the Albert had also turned back, and was managed for some days by McWilliam and William Stanger, the other officers and crew being unable to take part in the work. In ten days they reached the open sea. A few days later McWilliam himself was taken ill. Out of 145 Europeans who took part in the expedition 130 went down with fever and 40 died; but among 158 Africans there were only 11 cases of fever and 1 death. McWilliam reached England on 19 November 1841. After again serving two years afloat, McWilliam was sent on a special mission to the Cape de Verde Islands to inquire into the yellow fever which attacked the inhabitants of Boa Vista soon after the arrival of HMS Eclair. In 1847 he was appointed medical officer to the custom house, a post he retained till his death. In 1848 McWilliam was elected Fellow of the Royal Society, in 1858 he became Companion of the Order of the Bath, and in 1859 Fellow of the Royal College of Physicians of London. He was a member of the Epidemiological Society, and for several years acted as secretary. He was also one of the secretaries to the medical section of the International Statistical Congress held in London in 1860. He worked to ensure that naval medical officers obtained the official recognition of their rights. McWilliam died, 4 May 1862, from the effects of a fall in his own home, No. 14 Trinity Square, Tower Hill. He left a widow and several children.
Works
McWilliam's Journal of Practice from 'HMS Scout. In 1843 he brought out Medical History of the Niger Expedition, which was well received. It included a history of the fever, description, morbid anatomy, sequences, causes, treatment, with cases; with an account of the state of medicine among the Africans and of vaccination; a description of the ventilation of the ships, which was carried out on the plan adopted by David Boswell Reid for the houses of parliament; an abstract of meteorological observations; and a brief account of the geology of the Niger, condensed from the notes of William Stanger. McWilliam's report which established that yellow fever had been imported into Boa Vista by the Eclair, was presented to parliament, and printed in 1847. He contributed to medical and other journals, and also wrote:
Remarks on Dr. Gilbert King's Report on the Fever at Boa Vista, 1848.
Exposition of the Case of the Assistant-Surgeons of the Royal Navy, 3rd edit. 1850.
Further Observations on that portion of Second Report on Quarantine by General Board of Health which relates to Yellow Fever Epidemic on board H.M.S. Eclair, and at Boa Vista, 1852.