From 96c40987847009943727702f911bc6cf533ffebf Mon Sep 17 00:00:00 2001 From: Robert Chlumsky Date: Thu, 23 Sep 2021 12:41:53 -0400 Subject: [PATCH] Update download_hydat to have an option to bypass the keypress question (#165) * Update to download_hydat to bypass keypress with optional parameter * Update to add ask parameter to download_hydat * Update R/download.R Co-authored-by: Sam Albers * Update R/download.R Co-authored-by: Sam Albers * Update R/download.R Co-authored-by: Sam Albers * Update to NEWS.md with minor improvement to download_hydat Co-authored-by: Sam Albers --- NEWS.md | 3 +++ R/download.R | 16 ++++++++++++---- man/download_hydat.Rd | 4 +++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0f6432f..21b5bcf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +### MINOR IMPROVEMENT +* `download_hydat()` now has an `ask` parameter that can be used to bypass the keypress confirmation when downloading the HYDAT database (@rchlumsk, #165). + # tidyhydat 0.5.4 - When add a local timezone column, use the most common timezone in the data rather than the first one. This just seems more likely to be useful to users - Add more documentation to `realtime_add_local_datetime` to make how timezones are dealt with clearer (#157) diff --git a/R/download.R b/R/download.R index 4ccd5f5..baf3c47 100644 --- a/R/download.R +++ b/R/download.R @@ -19,6 +19,7 @@ #' @param dl_hydat_here Directory to the HYDAT database. The path is chosen by the `rappdirs` package and is OS specific and can be view by [hy_dir()]. #' This path is also supplied automatically to any function that uses the HYDAT database. A user specified path can be set though this is not the advised approach. #' It also downloads the database to a directory specified by [hy_dir()]. +#' @param ask Whether to ask (as \code{TRUE}/\code{FALSE}) if HYDAT should be downloaded. If \code{FALSE} the keypress question is skipped. #' @export #' #' @examples \dontrun{ @@ -26,7 +27,7 @@ #' } #' -download_hydat <- function(dl_hydat_here = NULL) { +download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) { if(is.null(dl_hydat_here)){ dl_hydat_here <- hy_dir() @@ -38,11 +39,18 @@ download_hydat <- function(dl_hydat_here = NULL) { } } - ans <- ask(paste("Downloading HYDAT will take ~10 minutes.","This will remove any older versions of HYDAT", - "Is that okay?", sep = "\n")) + if (!is.logical(ask)) stop("Parameter ask must be a logical") + + if (ask) { + ans <- ask(paste("Downloading HYDAT will take ~10 minutes.","This will remove any older versions of HYDAT", + "Is that okay?", sep = "\n")) + } else { + ans <- TRUE + green_message(paste0("Downloading HYDAT to ", normalizePath(dl_hydat_here))) + } + if (!ans) stop("Maybe another day...", call. = FALSE) - info(paste0("Downloading HYDAT.sqlite3 to ", crayon::blue(dl_hydat_here))) diff --git a/man/download_hydat.Rd b/man/download_hydat.Rd index 71c7bde..bf84ccd 100644 --- a/man/download_hydat.Rd +++ b/man/download_hydat.Rd @@ -4,12 +4,14 @@ \alias{download_hydat} \title{Download and set the path to HYDAT} \usage{ -download_hydat(dl_hydat_here = NULL) +download_hydat(dl_hydat_here = NULL, ask = TRUE) } \arguments{ \item{dl_hydat_here}{Directory to the HYDAT database. The path is chosen by the \code{rappdirs} package and is OS specific and can be view by \code{\link[=hy_dir]{hy_dir()}}. This path is also supplied automatically to any function that uses the HYDAT database. A user specified path can be set though this is not the advised approach. It also downloads the database to a directory specified by \code{\link[=hy_dir]{hy_dir()}}.} + +\item{ask}{Whether to ask (as \code{TRUE}/\code{FALSE}) if HYDAT should be downloaded. If \code{FALSE} the keypress question is skipped.} } \description{ Download the HYDAT sqlite database. This database contains all the historical hydrometric data for Canada's integrated hydrometric network.