There is a theory with quite a lot of weight to it suggesting that the classic Roman Legion relied a lot more on missiles than on their swords, and that a charge to engage in melee only happened after the enemy was disrupted by missiles (or if some other opportunity happened)
A suspicious number of military awards revolved around things like exposing yourself to danger to collect missiles from the battlefied (spears, rocks). A lot of legionary equipment, especially the scutum suddenly makes a lot more sense if you assume a legionary might spend hours exchanging missile fire with an enemy before closing with them.
The infamous self destructing pilum makes a lot of sense in this context too; it both fouls any shield it hits thus depriving the enemy of cover and cannot be collected and thrown back. Both qualities don’t really matter if all the Romans did was huck them and Leroy Jenkins at the enemy.
In most cultures swords were basically sidearms and/or status symbols, kind of like pistols today. The Romans would be a hell of an exception if they relied primarily on the sword
As always with the Legion, you have to specify When as well as What. The Legion started out as a simple decimal Phalanx of spearmen: there's historical and literary evidence that the original 'century' was 10 ranks deep and 10 files wide with about 80 of them armed with heavy spears, and the poorest 20% of the population unarmored and throwing javelins to disrupt the enemy before the spearmen 'got stuck in' and finished them off.
The first big change in this tactical method was to arm some of the spearmen with swords. This was, apparently, in imitation of their primary enemies, the Sabines, who had found that swords were more useful in rough country where the tight formation that made the spearmen so effective could not be maintained - and central Italy has a lot of rough country! However, the
Hastatii that carried the swords were in front of the
Principes - the 'primary' tactical force, who were still spearmen. By the time of the Punic Wars the Legion, then, consisted of
Velites - light infantry, no armor, javelins,
Hastatii, heavily armored men with the Scutarii big shield and a short sword adapted from the Spanish, the
Principes, now also with swords, armor and a big heavy shield, and the
Triarii - the 'third rank' in the rear, the most veteran of the troops and the 'last ditch' whenever things went completely wrong. They were still armed with Spears.
The Pilum, a heavy short-ranged javelin, may have been adopted from the Sabines, or from the Celtiberian (Spanish) heavy infantry, both of whom used a similar heavy javelin that could encumber shields or penetrate link mail armor if the target had already lost his shield. There is no evidence that it was ever carried by Roman spearmen. It was always associated with swordsmen, either the Hastatii, or Principes, or the Post-Marian Reform Legion in which all the heavy (armored) infantry in the Legion carried Sword and Pilum.
Early in the Imperial 1st century CE the 'classic' Legion of professional swordsmen started adding 'lanciarii' - spearmen - back into the ranks, because they were fighting a distressingly large number of cavalry, including Sarmatian Cataphractii who were armored men on armored horses with both long swords and lances.
By the 3rd - 4th centuries CE the mobile parts of the Legions - the professionals who were the Field Army, while the bulk of the Legion were now stationary garrison troops - were still carrying a big heavy shield and a long sword, but also a long heavy spear. And they were trained to use both spear and sword as needed. These troops combined all the advantages of the spear against cavalry and the sword in rough country against infantry and they were retained by the early post-Western Roman Empire Byzantine infantry of the 6th and 7th century.
The Legion was never primarily a 'missile' force. If it had been, the Imperial Roman Imperiium would not have hired so many auxiliary archers, slingers, javelin-throwers, horse archers, etc. who comprised the majority of the auxiliary forces for most of the Imperial era.
What made the Roman use of swordsmen possible was the wealth of the Roman state, which allowed them to maintain a long term, professional army - swordsmen have to practice a lot with their weapons to become and stay proficient with them, and that means they have to have someone else working to keep them paid and fed: the Roman Empire with (lowest estimate) 50,000,000 or more people used most of the Imperial taxes to pay for an army of about 500,000 men at most: 1% of the population, and after the plagues of the 3rd - 4th centuries that may have wiped out up to a third of the population, they couldn't even afford 1% any more.