Aloha.
I don't have a way yet to do an MWE with the problem but I can reproduce it in a current script. Here is the line that fails to execute when the entire script runs but does fine when it is directly executed.
It reverses the sign of some data. I'll see if this has the same behavior in R.app. If anyone sees something suggestive of the nature of the problem, pls advise.
I retract that last problem. I think the 'problem' has to do with the logic of order of the calculations that get flummoxed when things are repeated. User error.