Neil Neil - 7 months ago 33
R Question

How to get a ping response in R

I have a dataframe which has domain name column. I want to see which domain exist by pinging their domain names. I can get an individual ping response from following function.

ping <- function(x,stderr=FALSE,stdout=FALSE,...){
pingvec <- system2("ping",x,
if (pingvec == 0) TRUE else FALSE

[1] TRUE

Is there any R package where I can get ping response for entire column which has thousands of domain names.


It is not a good idea to use system() commands - as a general rule in any programming language. The main reasons are security and portability issues.

The pingr package provides a possibility to ping a remote server within R:

URLs <- c("", "")  
sapply(URLs, ping)
#[1,]       14.6       171
#[2,]       14.7       171
#[3,]       14.6       171

edit / comment

Looking at the source code of the functions pingr::ping() and pingr:::ping_os() it appears that the package does use a call to system(). Therefore, I think that security concerns remain, since the OS function ping could be redefined to do something completely different and possibly harmful. What the package does seem to resolve are portability problems, since different methods are called depending on the OS.