From 19dbe380a024965de3cd9e7236a2c48edf692b38 Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Sun, 21 Jun 2020 07:59:29 -0400 Subject: [PATCH] reachable --- NAMESPACE | 1 + R/reachable.R | 11 +++++++++++ README.md | 6 ++++-- man/reachable.Rd | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 R/reachable.R create mode 100644 man/reachable.Rd diff --git a/NAMESPACE b/NAMESPACE index 9b33ab6..f058805 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(bitbar_plugins_dir) export(new_bitbar_script) export(open_bitbar_dir) export(r_logo_small) +export(reachable) import(httr) import(miniUI) import(shiny) diff --git a/R/reachable.R b/R/reachable.R new file mode 100644 index 0000000..5156513 --- /dev/null +++ b/R/reachable.R @@ -0,0 +1,11 @@ +#' Is the internet accessible? +#' +#' @param fqdn_or_ip FQDN or ip to use for reachability testing. defaults to google dns +#' @export +reachable <- function(fqdn_or_ip = "8.8.8.8") { + + res <- sys::exec_internal("/usr/sbin/scutil", args = c("-r", fqdn_or_ip[1])) + + return(res$status == 0) + +} \ No newline at end of file diff --git a/README.md b/README.md index 1e215dd..373167e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ performance). The following functions are implemented: - `add_entry`: Add an entry to the menu + - `applescript`: Execute AppleScript and Return Results - `b64_image`: Return a base64 encoded string of an image (local filesystem or URL) - `bitbar_plugins_dir`: BitBar plugins directory @@ -52,6 +53,7 @@ The following functions are implemented: script - `open_bitbar_dir`: Open BitBar Plugins Directory in the Finder - `r_logo_small`: Images that come with the package + - `reachable`: Is the internet accessible? There are also two RStudio Addins, one with a GUI for entering in the script metadata & starting a new BitBar {bitbar} script and one for @@ -99,8 +101,8 @@ new_bitbar_script( | Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | | :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: | -| R | 10 | 0.91 | 191 | 0.94 | 51 | 0.69 | 79 | 0.66 | -| Rmd | 1 | 0.09 | 13 | 0.06 | 23 | 0.31 | 41 | 0.34 | +| R | 12 | 0.92 | 221 | 0.94 | 63 | 0.73 | 122 | 0.75 | +| Rmd | 1 | 0.08 | 13 | 0.06 | 23 | 0.27 | 41 | 0.25 | ## Code of Conduct diff --git a/man/reachable.Rd b/man/reachable.Rd new file mode 100644 index 0000000..3399959 --- /dev/null +++ b/man/reachable.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reachable.R +\name{reachable} +\alias{reachable} +\title{Is the internet accessible?} +\usage{ +reachable(fqdn_or_ip = "8.8.8.8") +} +\arguments{ +\item{fqdn_or_ip}{FQDN or ip to use for reachability testing. defaults to google dns} +} +\description{ +Is the internet accessible? +}