1/2 day trip from Edinburgh to St. Andrews

We want to take a 1/2 day trip from Edinburgh city to St. Andrew's (we don't want to take the full day or 9 hour tour).
What would be recommended as the best option: a private driver, a taxi or rail?