(I'm a physician who used to work with large pharma companies on trial design and trial innovation.)
I think the cost of R&D in pharma that we hear about is sometimes vastly inflated and sometimes pretty accurate, but definitely oftentimes misapplied (especially by pharma).
On the whole, trials are expensive. Sure, there's the pre-clinical stuff -- basic research that you're alluding to. There's the stuff that is R&D but fails in the pipeline at some point. There's animal studies.
But in most cases, most of the cost comes from human trials (Phase I-III, and mostly Phase III), which can sometimes span dozens of countries and tens of thousands of participants. For some drugs, the Phase III trial(s) account for over 80% of the total R&D cost. Even when they are relatively small trials (as in this CAR-T therapy trial), the administrative and logistical effort to implement something like this is immense. The whole point of these trials is to collect data, and so that data is subject to the highest amount of scrutiny of any data in any medical enterprise. If you come into my clinic for a pre-op before surgery and I measure your blood pressure to be 140/85, give or take a few (oh wait maybe I used the wrong cuff size, lemme try again, oh it's pretty close), that's fine. But if you come into my clinic because you're a participant on a trial for drug X, and I measure it to be 140/85... I better be damn sure that's right (and the study coordinator at my clinic, and the pharma company, and the FDA), even if drug X isn't a blood pressure drug. We've seen cases where certain innocuous data discrepancies trigger central study monitors (study employees) being flown out to remote clinics to manually verify paper records or equipment logs to confirm/reconcile errors. Inaccuracies can cause you to miss things, or patients to be harmed, or can cause a study or a clinic or a hospital to be shut out from performing research again. And of course it can make the difference between a drug approval and failure. It's a lot of resources around the idea of data integrity.
So even small versions of these types of trials can be very expensive.
Now, is it TOO expensive? We often hear about the cost of bringing a drug to market to be around $1B. (Some studies have put it over $2B when you account for failed drugs, etc.) This may or may not be right, but let's not forget, the pharma industry makes more profit than just about any other industry. And the way CMS and insurers agree to pay for medicines... well, pharma has a lot of freedom in pricing (upwards).
You've hit on a lot of things that make the release of some new drugs/devices/therapies less expensive than we are commonly led to believe: reusing previous data, getting new approval for a specific enantiomer of a previously approved racemic drug, making cosmetic updates to existing devices, the tricks go on and on and on. And pharma keeps saying "R&D is so expensive! This drug should definitely be 2X more expensive than the one we're replacing." Planned obsolescence is a pain with your smartphone; it's a lot worse with your insulin pump or even the insulin itself! And one outcome of the high cost of large trials is that pharma does more of these types of un-innovation in some cases, which (due to the patent and regulatory and reimbursement systems) simply give pharma a free pass at making easy money off of our backs.
The high cost of trials also leads to really high prices of "true" innovation, such as in CAR-T trials. This type of therapy (like a lot of new oncology therapy) is highly customized, and no longer simply some chemical compound you make in a factory and then ship all over the world. You have to take a patient's own cells/fluid/materials/etc, process them, and then make modifications (in some cases unique to the patient), and then return the processed product (to the same patient). This is indeed highly costly on top of the cost of performing a lengthy trial, where for certain rare and/or terminal diseases your study endpoints are pretty tough to capture (um, did the patient die? uh, how long do we wait?).