r-lib / pingr

ICMP and TCP ping and related tools
http://r-lib.github.io/pingr/
Other
34 stars 8 forks source link

Cannot suppress warnings or messages from is_online() #9

Closed ramiromagno closed 4 years ago

ramiromagno commented 5 years ago

hi @gaborcsardi,

It seems it is not possible to suppress either warnings or messages from is_online(), perhaps because they are neither. Still, it would be nice to be able to quiet is_online()...

> suppressMessages(pingr::is_online())
ping: google-public-dns-a.google.com: Temporary failure in name resolution
ping: b.resolvers.Level3.net: Temporary failure in name resolution
connect: Network is unreachable
connect: Network is unreachable
[1] FALSE
> suppressWarnings(pingr::is_online())
ping: google-public-dns-a.google.com: Temporary failure in name resolution
ping: b.resolvers.Level3.net: Temporary failure in name resolution
connect: Network is unreachable
connect: Network is unreachable
[1] FALSE

I believe this results from using the system() function:

https://github.com/r-lib/pingr/blob/6da09409ba51a01bd16fdf782e06d74a9d32a469/R/ping-package.r#L65

Could you not change that system call to:

output <- suppressWarnings(
                   system(os$cmd, intern = ! verbose,
                               ignore.stdout = TRUE, ignore.stderr = TRUE)
) 
gaborcsardi commented 4 years ago

After switching to processx (#8), no messages are shown.