Capital of Statistics » R Language

  1. yihui
    Key Master

    Because we can shut down the Windows system by the command shutdown, we may also use the R function shell() to execute the command. For instance, shell("shutdown -s -t 10") will shut down your computer after 10 seconds (DON'T run the code before you have saved and closed all the programs - I'll not be responsible for your data lost!). If you regret doing so, you can execute shell("shutdown -a") immediately.

    I'm not sure whether the command is the same under Linux. (AFAIR, it's the same command but with different options?)

    We may include this function in the package fun as well:

    shutdown = function(wait = 0,  timeout = 10) {
        Sys.sleep(wait)
        # .Platform$OS.type? Windows? Linux?
        shell(sprintf("shutdown -s -t %d", timeout))
    }
    

    I think this function can be useful when we want our computer to be shut down automatically after a (time-consuming) task.

    Posted 2 years ago #
  2. yanlinlin82
    Key Master

    Linux use the 'shutdown' command too, but with different parameters.

    We can use following command to shutdown immediately:
    $ shutdown -h now
    Or following command to shutdown after 30 minutes:
    $ shutdown -h +30
    Or shutdown at 23:30:
    $ shutdown -h 23:30

    So the function can be:

    shutdown = function(wait = 0, timeout = 10) {
      Sys.sleep(wait)
      shell(
        paste(sep = "",
          "shutdown ",
          switch(.Platform$OS.type,
            windows = sprintf("-s -t %d", timeout),
            unix = "-h now")
          )
        )
    }
    shutdown()
    Posted 2 years ago #
  3. Taiyun
    Moderator

    Cool, Wonderful job!

    Posted 2 years ago #
  4. yihui
    Key Master

    I realized the argument timeout is unnecessary, so this will be enough:

    shutdown <-
    function(wait = 0) {
        Sys.sleep(wait)
        ifelse(.Platform$OS.type == "windows", shell("shutdown -s -t 0"),
            system("shutdown -h now"))
    }

    This function has gone to fun now. You can see it in R-Forge.

    Posted 2 years ago #
  5. sanjidao01
    Member

    thanks very much!! it s very helpful for me
    _________________________________________
    Dear players, do you need [url=http://www.storeingame.com/]Gold for WOW[/url]? We provide you with [url=http://www.2joygame.com/]Wow Gold[/url], [url=http://www.2joygame.com/]cheap Wow Gold[/url], including World of Warcraft EU Gold and World of Warcraft US Gold. Also we supply Metin2 Yang and Metin2 Gold to Metin2 players. Besides we also offer WOW Level Power Leveling.

    Posted 2 years ago #

RSS feed for this topic

Reply

You must log in to post.