Is there a way to prevent corpses from disappearing?
For the PC version there's a mod called Piles of Corpses.
According to the modder Fallout 4's/the mod's (not explicitly stated which one) default values are:
---iHoursToClearCorpses - 24 [1 day] (Resets when you return to the cell) ---iRemoveExcessDeadComplexCount - 3
---iRemoveExcessDeadCount - 15
---iRemoveExcessDeadComplexTotalActorCount - 20
---iRemoveExcessDeadTotalActorCount - 20
After installing the mod you can edit based on your preferences. Be sure to take backups of your save files before using mods.
Fallout 4 engine maybe limited to 1000 bodies as the modder uses "999 supermutants and a piper" in the demonstration screenshot:
As per @Nelson, if we assume things work the same as in Skyrim, then an area should reset in 3-30 days, depending on some variables. So, if you visit at least every three days, the corpses should stay.
I had a playthrough where I used the Red Rocket Truck Stop as my main settlement, and the molerats from the initial encounter there remained for the entire game. That character never got local leader, so I'm sure I visited the truck stop at least every three days.