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 2 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
15 changes: 11 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) {
rchlumsk marked this conversation as resolved.
Show resolved Hide resolved

if(is.null(dl_hydat_here)){
dl_hydat_here <- hy_dir()
Expand All @@ -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.logical(ask)) stop("Parameter ask must be a boolean")
rchlumsk marked this conversation as resolved.
Show resolved Hide resolved

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
}

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.