Mark Carney has been sworn in as the prime minister of Canada, assuming office amid threats from the United States.