Ping a website in R

前端 未结 4 1380
难免孤独
难免孤独 2020-12-03 17:39

I would like to create a script in R that pings a given website. I haven\'t found any information about this specific for R.

To start with, all I need is the informa

4条回答
  •  心在旅途
    2020-12-03 18:11

    RCurl::url.exists works for localhost (where ping doesn't always) and is faster than RCurl::getURL.

    > library(RCurl)
    > url.exists("google.com")
    [1] TRUE
    > url.exists("localhost:8888")
    [1] TRUE
    > url.exists("localhost:8012")
    [1] FALSE
    

    Note that it is possible to set the timeout (which by default is rather long)

    > url.exists("google.com", timeout = 5) # timeout in seconds
    [1] TRUE
    

提交回复
热议问题