Disable auto-update from R (Windows)
[This article was first published on [the] joint posterior distribution, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
There are two major threats to complex MCMC estimations:Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
- 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DisAutoUpdate = function(set="off") { | |
if(Sys.getenv("OS")=="Windows_NT" ) { | |
if(set="off") { write("Net stop wuauserv",file="disauto.bat")} else { | |
write("Net start wuauserv",file="disauto.bat")} | |
prog <- paste(gsub("/","\\\\",getwd()),"\\","disauto.bat",sep="") | |
user <- paste(Sys.getenv("USERDOMAIN"), Sys.getenv("USERNAME"),sep="\\") | |
system(paste("CMD /k runas /user:\"", user ,"\" ",prog,sep=""),invisible=FALSE, show.output.on.console=FALSE) | |
} else {"Only needed on Windows"} | |
} |
To leave a comment for the author, please follow the link and comment on their blog: [the] joint posterior distribution.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.