R/monitor_bestTimezone.R

Defines functions monitor_bestTimezone

Documented in monitor_bestTimezone

#' @export
#'
#' @title Return the most common timezone
#'
#' @param monitor \emph{mts_monitor} object.
#'
#' @description Evaluates all timezones in \code{monitor} and returns the
#' most common one. In the case of a tie, the alphabetically first one is
#' returned.
#'
#' @return A valid \code{base::OlsonNames()} timezone.
#'

monitor_bestTimezone <- function(
  monitor = NULL
) {

  # ----- Validate parameters --------------------------------------------------

  MazamaCoreUtils::stopIfNull(monitor)

  # ----- Find most common timezone --------------------------------------------

  timezoneTable <- sort(table(monitor$meta$timezone), decreasing = TRUE)
  timezone <- names(timezoneTable)[1]

  if ( !timezone %in% OlsonNames() )
    stop(sprintf("timezone '%s' is not a valid OlsonNames() timezone", timezone))

  # ----- Return ---------------------------------------------------------------

  return(timezone)

}

Try the AirMonitor package in your browser

Any scripts or data that you put into this service are public.

AirMonitor documentation built on Aug. 26, 2023, 1:08 a.m.