Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update download_hydat to have an option to bypass the keypress question #165

Merged
merged 6 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
rchlumsk marked this conversation as resolved.
Show resolved Hide resolved
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.