Both are great universities, my cousin studies in St. Andrews but I applied to Edinburgh (and I'm definitely accepting their offer). My cousin's doing IR as an outside course, but he doesn't like it, says it's too much about politics or something. He loves the Econ and Philosophy courses though. But, while he's enjoying the university, he also said that St. Andrews has about 3 streets and the whole place is about as big as a shopping mall. He did say that he has to go to Dundee for shopping, but I think he may have been exaggerating. Though, it IS beautiful, but so is Edinburgh.
I think with Edinburgh you get a more rounded experience, and that's just my opinion. You get city life (it's no London but it's a bit more urban than St. Andrews), pretty meadows, castles, history, culture, festivals, as well as an amazing education. Oh and they both have a LOT of international students apparently, and are very well respected worldwide, though as people have said Edinburgh edges St. Andrews on the global rankings.