From e0b2f98673c91d908a27c3e01ff516fcc14df9ed Mon Sep 17 00:00:00 2001 From: rchlumsk Date: Tue, 21 Sep 2021 11:34:03 -0400 Subject: [PATCH 1/6] Update to download_hydat to bypass keypress with optional parameter --- R/download.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/R/download.R b/R/download.R index 4ccd5f5..6bf6d69 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 ans Answer (as boolean) can be provided to avoid keypress in function execution. #' @export #' #' @examples \dontrun{ @@ -26,7 +27,7 @@ #' } #' -download_hydat <- function(dl_hydat_here = NULL) { +download_hydat <- function(dl_hydat_here = NULL, ans=NULL) { if(is.null(dl_hydat_here)){ dl_hydat_here <- hy_dir() @@ -38,11 +39,17 @@ 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.null(ans)) { + ans <- ask(paste("Downloading HYDAT will take ~10 minutes.","This will remove any older versions of HYDAT", + "Is that okay?", sep = "\n")) + } else { + if (ans != TRUE & ans != FALSE) { + stop("Parameter ans must be a boolean") + } + } + if (!ans) stop("Maybe another day...", call. = FALSE) - info(paste0("Downloading HYDAT.sqlite3 to ", crayon::blue(dl_hydat_here))) From f8480074015fa3e408e3d4c1809750ebc0605894 Mon Sep 17 00:00:00 2001 From: rchlumsk Date: Wed, 22 Sep 2021 07:14:01 -0400 Subject: [PATCH 2/6] Update to add ask parameter to download_hydat --- R/download.R | 12 ++++++------ man/download_hydat.Rd | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/R/download.R b/R/download.R index 6bf6d69..a56df12 100644 --- a/R/download.R +++ b/R/download.R @@ -19,7 +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 ans Answer (as boolean) can be provided to avoid keypress in function execution. +#' @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{ @@ -27,7 +27,7 @@ #' } #' -download_hydat <- function(dl_hydat_here = NULL, ans=NULL) { +download_hydat <- function(dl_hydat_here = NULL, ask=TRUE) { if(is.null(dl_hydat_here)){ dl_hydat_here <- hy_dir() @@ -39,13 +39,13 @@ download_hydat <- function(dl_hydat_here = NULL, ans=NULL) { } } - if (is.null(ans)) { + if (!is.logical(ask)) stop("Parameter ask must be a boolean") + + 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 { - if (ans != TRUE & ans != FALSE) { - stop("Parameter ans must be a boolean") - } + ans <- TRUE } if (!ans) stop("Maybe another day...", call. = FALSE) 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. From 739e78b4f32bd23ca7d8ada8abd8dce82b0cbf1e Mon Sep 17 00:00:00 2001 From: Robert Chlumsky Date: Thu, 23 Sep 2021 10:12:01 -0400 Subject: [PATCH 3/6] Update R/download.R Co-authored-by: Sam Albers --- R/download.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/download.R b/R/download.R index a56df12..3030e18 100644 --- a/R/download.R +++ b/R/download.R @@ -27,7 +27,7 @@ #' } #' -download_hydat <- function(dl_hydat_here = NULL, ask=TRUE) { +download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) { if(is.null(dl_hydat_here)){ dl_hydat_here <- hy_dir() From a31acb52cb3fdd953dea0c1d6aea84764d8ee897 Mon Sep 17 00:00:00 2001 From: Robert Chlumsky Date: Thu, 23 Sep 2021 10:12:17 -0400 Subject: [PATCH 4/6] Update R/download.R Co-authored-by: Sam Albers --- R/download.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/download.R b/R/download.R index 3030e18..3207e65 100644 --- a/R/download.R +++ b/R/download.R @@ -39,7 +39,7 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) { } } - if (!is.logical(ask)) stop("Parameter ask must be a boolean") + 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", From 19dca330398c2d1e7a7308d5c043ea995867ed6b Mon Sep 17 00:00:00 2001 From: Robert Chlumsky Date: Thu, 23 Sep 2021 10:12:31 -0400 Subject: [PATCH 5/6] Update R/download.R Co-authored-by: Sam Albers --- R/download.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/download.R b/R/download.R index 3207e65..baf3c47 100644 --- a/R/download.R +++ b/R/download.R @@ -46,6 +46,7 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) { "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) From 2f0cfda3694943c3ba08d4eee385b837e5ca7a6a Mon Sep 17 00:00:00 2001 From: rchlumsk Date: Thu, 23 Sep 2021 10:28:07 -0400 Subject: [PATCH 6/6] Update to NEWS.md with minor improvement to download_hydat --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) 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)