Skip to content

Commit

Permalink
Update download_hydat to have an option to bypass the keypress questi…
Browse files Browse the repository at this point in the history
…on (#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 <[email protected]>

* Update R/download.R

Co-authored-by: Sam Albers <[email protected]>

* Update R/download.R

Co-authored-by: Sam Albers <[email protected]>

* Update to NEWS.md with minor improvement to  download_hydat

Co-authored-by: Sam Albers <[email protected]>
  • Loading branch information
rchlumsk and boshek authored Sep 23, 2021
1 parent 5ee7171 commit 96c4098
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 12 additions & 4 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
#' @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{
#' download_hydat()
#' }
#'

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()
Expand All @@ -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)))


Expand Down
4 changes: 3 additions & 1 deletion man/download_hydat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 96c4098

Please sign in to comment.