Some very good points have been made above and as I know little about warfare in the 1700s I cannot really offer very much.
Perhaps the biggest change in warfare was that the majority of infantry in the Napoleonic era manoeuvred in column formation whilst in much closer proximity to the enemy than they had previously, forming line only when necessary. As these columns could form into square very rapidly, they were also fairly secure against cavalry. The option to stand and repulse cavalry in line was therefore perhaps no longer necessary.
The British were an exception to this rule, and although there are many instances of them manoeuvering in quarter distance columns in the presence of enemy cavalry in order to rapidly form square if necessary, there is no doubt that in general they still favoured deployment into line while still outside effective artillery range (1200-1500 paces).
In the Peninsula there were many occasions when British battalions stood in line to receive, and repulse, French cavalry.
At Fuentes de Onoro, the 51st Regiment, Chasseurs Britanniques and Brunswick Oels (and no doubt the Portuguese Brigade) all repulsed cavalry charges in line formation during the retreat of the 7th Division. The 42nd Regiment of the 1st Division also performed the same feat.
At Albuera, both the Fusilier Brigade and Harvey's Portuguese Brigade of the 4th Division repulsed French cavalry charges in line.
At El Bodon the 5th Regiment charged, and defeated, French cavalry while in line.
At Salamanca, the 5th and 45th Regiments of the 3rd Division repulsed a French cavalry charge directed against their flank by fire in line, by wheeling back a few companies.
Also at Salamanca, Hulse's brigade fought off a brigade of Boyer's dragoons by volleys from a line formation.
As far as I am aware, there are no examples in the Peninsula of a British or Portuguese line, attacked frontally, being ridden down by French cavalry and the suggestion that the British formed square as often as they could must be questioned.
It is also not correct that the British discarded the 2 deep line at Waterloo. The 4 deep line was used by three brigades (Adam, Maitland and Halkett) late in the day when it was anticipated that the French were launching a combined arms assault, other British and KGL brigades forming 2 deep to face infantry throughout the day. Maitland wrote:
"About 7 o'clock, the Duke of Wellington, aware of the enemy's preparations for a new attack, desired me to form the 1st Brigade of Guards in line 4 files deep, His Grace expecting that the French Cavalry would take part in the affair."
The purpose of the 4 deep line was to receive this combined assault and was not a new innovation, having been used as early as 1808, at Vimiero:
"We were then halted, and as the enemy appeared to have gone completely off, our men were allowed to stand at ease. While resting in this manner we suddenly observed a column of the enemy, which, it seems, had suddenly concealed in a village on the opposite heights, make a dash down as if they meant to attack us, while a body of cavalry at the same time appeared on our right flank, threatening to turn and attack us in that flank. We were instantly ordered to form four deep, which formation afforded the advantage of showing a front to meet the enemy in line, and at the same time of sufficient strength to resist cavalry."