listed on r-bloggers.com

Freitag, 21. Januar 2011

Disable auto-update from R (Windows)

There are two major threats to complex MCMC estimations:
  • Wrong energy settings (hibernate after 2 hours of inactivity)
  • Automatic Updates (install updates at 3 a.m.)

I thought about the latter threat. At times, you may hand some R code to other co-workers, especially when you need to estimate lots of different models in a short period of time. If they have auto-updates enabled, your results are quickly in jeopardy. While automatically saving the workspace [if(rep==10000) save.image("save.RData")] is definitely a very good idea, deactivating automatic updates on windows is still important for long-term calculations.
Therefore I thought about ways to deactivate automatic updates from within R. A major obstacle is UAC (user account control) which turns your administrator account into something ... with less right. Windows frequently asks for privilege elevation. Sadly, elevation does not work without further administrative tools, which you will not find on every PC around. Therefore I decided to use the "runas" command, which will ask the user for her password once.
Although this is not a perfect solution yet, it is also a very nice example on some interesting functions: paste, sub, system.

[EDIT]
"runas" apparently does not work with "net stop" command, therefore a .bat file needs to be created which can be started using runas. The .bat is created from within R.

[EDIT2]
Random John reminded my that an option to turn auto update back on would be nice. Well, I added that.


4 Kommentare:

  1. Would love to see the disauto.bat file...

    AntwortenLöschen
  2. write("Net stop wuauserv",file="disauto.bat") it's created from within, the net stop command does not work with runas, thus the bat file is needed.

    AntwortenLöschen
  3. So, in the spirit of best practice, it looks like you would need to do the reverse as well, right? So an opposite function (or option within this function) to net start wuauserv, which is run after the MCMC is over. Is there a way to get the state of Windows update within R so that you can find you can turn it off and then restore it only if it was on?

    Just thinking out loud here.

    AntwortenLöschen
  4. I have to think about how to check the status of windows update. In the meantime, I updated the main function and added a parameter "set" which can be set "on" or "off".

    AntwortenLöschen