From 09d50c08d599be31b0c41ddf0afe592c08c6e355 Mon Sep 17 00:00:00 2001 From: edavidaja Date: Wed, 21 Aug 2024 12:30:37 -0700 Subject: [PATCH] update regex to handle sub-millisecond response times the regular expression used to search through ping output for response times only matches on an equals sign this change modifies: - the regular expression in ping_os() so that less than or equals will both produce matches - the capture group in ping() is modified accordingly response time will be reported as 1ms. closes #24 --- NEWS.md | 2 ++ R/ping-package.R | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8b1459a..687c0a1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # pingr (development version) +* `ping()` now handles sub-millisecond response times (#24). + # pingr 2.0.3 * `ping_port()` now correctly prints the port if `version = TRUE`. diff --git a/R/ping-package.R b/R/ping-package.R index d594cee..b3c69c2 100644 --- a/R/ping-package.R +++ b/R/ping-package.R @@ -72,7 +72,7 @@ ping <- function(destination, continuous = FALSE, verbose = continuous, if (!continuous) { timings <- grep(os$regex, output, value = TRUE, perl = TRUE) - times <- sub(os$regex, "\\1", timings, perl = TRUE) + times <- sub(os$regex, "\\2", timings, perl = TRUE) res <- as.numeric(times) length(res) <- count res @@ -132,7 +132,7 @@ ping_os <- function(destination, continuous, count, timeout) { ) } - list(cmd = cmd, env = env, regex = "^.*time=(.+)[ ]?ms.*$") + list(cmd = cmd, env = env, regex = "^.*time(=|<)(.+)[ ]?ms.*$") } #' Is the computer online?