Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shutdown Windows after simulation

Tags:

r

I want R to shutdown my computer after my (extensive) simulation and saving results, is this possible?

like image 264
Maciej Avatar asked Aug 16 '12 05:08

Maciej


People also ask

How do I automate Windows shutdown?

From the Start menu, open the Run dialog box or you can Press the "Window + R" key to open the RUN window. Type "shutdown -s -t <number in seconds>" and press Enter Key. For example, if you want to shut down your PC/laptop after 10 minutes then, type: shutdown -s -t 600.

How can I schedule my PC to shut down?

To create a shutdown timer manually, open Command Prompt and type the command shutdown -s -t XXXX. The "XXXX" should be the time in seconds you want to elapse before the computer shuts down. For instance, if you want the computer to shut down in 2 hours, the command should look like shutdown -s -t 7200.


2 Answers

Yes, look at the function shutdown in the package fun.

The flags for system command shutdown depends on your operating system, the function simply calls the appropriately flagged command.

fun::shutdown

function (wait = 0) 
{
    Sys.sleep(wait)
    ifelse(.Platform$OS.type == "windows", shell("shutdown -s -t 0"), 
        system("shutdown -h now"))
}
like image 104
mnel Avatar answered Sep 27 '22 16:09

mnel


R can send commands to the system with ?system, and so whatever is required for Windows can be done with that:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/shutdown.mspx?mfr=true

R has a .Last() function controlled by quit() (or q()) with its runLast argument, so this is where you would send the shutdown commands via system, so that it occurs after quitting R. Saving objects with R is done with save or save.image, though there is a default to save as well with quit().

like image 34
mdsumner Avatar answered Sep 27 '22 15:09

mdsumner