Thanks for that, the code block thing makes it look so much cleaner.
Right, okay thank you very much for your help. So your code worked fine, as expected. So I know there was something wrong in what I was doing. For a bit of context, I work for the Government and this is a large Monte Carlo Simulation which generates lots of tables and pretty pictures (graphics). The problem here is when the code runs and those tables are generated View() is executed and rstudioapi::documentSave() was not working because it was no longer the tab displayed. At lest that is my theory because when I use
rstudioapi::documentSaveAll()
It works fine. Of course it will save all open scripts but, that is fine with me.
So this comes comes down to my programming ignorance as an economist. So I really do appreciate your time and effort today. Thank you.