Oh,
sorry, I didn't saw your script. I think if you simply use $TM_FILEPATH it should work.
What's about to use the R bundle "Tidy" function. It makes usage of R's internal formatter.
Can you post me the formatted style to me privately (if the code is not confidential, of course) to see the difference, since I'm still looking for a nice prettifier for R code.
Cheers, --Hans