From ea04835c69f0dd59023f209eddbe7b45b41d80c0 Mon Sep 17 00:00:00 2001 From: Nicolas Casajus Date: Thu, 8 Feb 2024 10:56:33 +0100 Subject: [PATCH] feat: add option to skip message to dl latest version --- R/gets.R | 35 ++++++++++++++++++++++------------- R/utils.R | 36 ++++++++++++++++++++---------------- man/get_data.Rd | 30 +++++++++++++++++++++++++++--- man/get_forcis_db.Rd | 12 +++++++++++- 4 files changed, 80 insertions(+), 33 deletions(-) diff --git a/R/gets.R b/R/gets.R index 0179d46..d5b3ced 100644 --- a/R/gets.R +++ b/R/gets.R @@ -10,6 +10,10 @@ #' #' @param version a `character` of length 1. The version number of the #' FORCIS database. Default is the latest version. +#' +#' @param check_for_update a `logical`. If `TRUE` (default) it will check if a +#' newer version of the FORCIS database is available on Zenodo and ask user +#' to download it. #' #' @param overwrite a `logical`. If `TRUE` it will override the downloaded #' files of the FORCIS database. Default is `FALSE`. @@ -33,7 +37,7 @@ #' list.files(path_to_save_db, recursive = TRUE) #' } -get_forcis_db <- function(path = ".", version = NULL, +get_forcis_db <- function(path = ".", version = NULL, check_for_update = TRUE, overwrite = FALSE, timeout = 60) { ## Check args ---- @@ -54,7 +58,7 @@ get_forcis_db <- function(path = ".", version = NULL, ## Check/set version ---- - version <- set_zen_version(version) + version <- set_zen_version(version, ask = check_for_update) ## Create outputs directory if required ---- @@ -119,7 +123,8 @@ NULL #' @export get_plankton_nets_data <- function(path = ".", version = NULL, - overwrite = FALSE, timeout = 60) { + check_for_update = TRUE, overwrite = FALSE, + timeout = 60) { ## Check args ---- @@ -129,7 +134,7 @@ get_plankton_nets_data <- function(path = ".", version = NULL, ## Check/set version ---- - version <- set_zen_version(version) + version <- set_zen_version(version, ask = check_for_update) ## Build outputs directory ---- @@ -200,7 +205,8 @@ get_plankton_nets_data <- function(path = ".", version = NULL, #' @export get_pump_data <- function(path = ".", version = NULL, - overwrite = FALSE, timeout = 60) { + check_for_update = TRUE, overwrite = FALSE, + timeout = 60) { ## Check args ---- @@ -210,7 +216,7 @@ get_pump_data <- function(path = ".", version = NULL, ## Check/set version ---- - version <- set_zen_version(version) + version <- set_zen_version(version, ask = check_for_update) ## Build outputs directory ---- @@ -281,7 +287,8 @@ get_pump_data <- function(path = ".", version = NULL, #' @export get_cpr_north_data <- function(path = ".", version = NULL, - overwrite = FALSE, timeout = 60) { + check_for_update = TRUE, overwrite = FALSE, + timeout = 60) { ## Check args ---- @@ -291,7 +298,7 @@ get_cpr_north_data <- function(path = ".", version = NULL, ## Check/set version ---- - version <- set_zen_version(version) + version <- set_zen_version(version, ask = check_for_update) ## Build outputs directory ---- @@ -360,8 +367,9 @@ get_cpr_north_data <- function(path = ".", version = NULL, #' @rdname get_data #' @export -get_cpr_south_data <- function(path = ".", version = NULL, - overwrite = FALSE, timeout = 60) { +get_cpr_south_data <- function(path = ".", version = NULL, + check_for_update = TRUE, overwrite = FALSE, + timeout = 60) { ## Check args ---- @@ -371,7 +379,7 @@ get_cpr_south_data <- function(path = ".", version = NULL, ## Check/set version ---- - version <- set_zen_version(version) + version <- set_zen_version(version, ask = check_for_update) ## Build outputs directory ---- @@ -442,7 +450,8 @@ get_cpr_south_data <- function(path = ".", version = NULL, #' @export get_sediment_trap_data <- function(path = ".", version = NULL, - overwrite = FALSE, timeout = 60) { + check_for_update = TRUE, overwrite = FALSE, + timeout = 60) { ## Check args ---- @@ -452,7 +461,7 @@ get_sediment_trap_data <- function(path = ".", version = NULL, ## Check/set version ---- - version <- set_zen_version(version) + version <- set_zen_version(version, ask = check_for_update) ## Build outputs directory ---- diff --git a/R/utils.R b/R/utils.R index 3997cc9..679e17f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -195,7 +195,7 @@ check_zen_version <- function(version) { #' #' @noRd -set_zen_version <- function(version) { +set_zen_version <- function(version, ask = TRUE) { check_zen_version(version) @@ -220,21 +220,25 @@ set_zen_version <- function(version) { } } - if (version != latest_version) { - - answer <- readline(paste0("A newer version of the FORCIS database is ", - "available. Do you want to download it [Y/n]? ")) - - if (answer == "") answer <- "y" - - answer <- tolower(answer) - - if (!(answer %in% c("y", "n"))) { - stop("Please type 'y' or 'n'", call. = FALSE) - } - - if (answer == "y") { - version <- latest_version + if (ask) { + + if (version != latest_version) { + + answer <- readline(paste0("A newer version of the FORCIS database is ", + "available. ", + "Do you want to download it [Y/n]? ")) + + if (answer == "") answer <- "y" + + answer <- tolower(answer) + + if (!(answer %in% c("y", "n"))) { + stop("Please type 'y' or 'n'", call. = FALSE) + } + + if (answer == "y") { + version <- latest_version + } } } diff --git a/man/get_data.Rd b/man/get_data.Rd index b6a7181..83ef84f 100644 --- a/man/get_data.Rd +++ b/man/get_data.Rd @@ -12,19 +12,39 @@ get_plankton_nets_data( path = ".", version = NULL, + check_for_update = TRUE, overwrite = FALSE, timeout = 60 ) -get_pump_data(path = ".", version = NULL, overwrite = FALSE, timeout = 60) +get_pump_data( + path = ".", + version = NULL, + check_for_update = TRUE, + overwrite = FALSE, + timeout = 60 +) -get_cpr_north_data(path = ".", version = NULL, overwrite = FALSE, timeout = 60) +get_cpr_north_data( + path = ".", + version = NULL, + check_for_update = TRUE, + overwrite = FALSE, + timeout = 60 +) -get_cpr_south_data(path = ".", version = NULL, overwrite = FALSE, timeout = 60) +get_cpr_south_data( + path = ".", + version = NULL, + check_for_update = TRUE, + overwrite = FALSE, + timeout = 60 +) get_sediment_trap_data( path = ".", version = NULL, + check_for_update = TRUE, overwrite = FALSE, timeout = 60 ) @@ -36,6 +56,10 @@ database has been (or will be) saved.} \item{version}{a \code{character} of length 1. The version number of the FORCIS database. Default is the latest version.} +\item{check_for_update}{a \code{logical}. If \code{TRUE} (default) it will check if a +newer version of the FORCIS database is available on Zenodo and ask user +to download it.} + \item{overwrite}{a \code{logical}. If \code{TRUE} it will override the downloaded files of the FORCIS database. Default is \code{FALSE}.} diff --git a/man/get_forcis_db.Rd b/man/get_forcis_db.Rd index e529c76..60691b4 100644 --- a/man/get_forcis_db.Rd +++ b/man/get_forcis_db.Rd @@ -4,7 +4,13 @@ \alias{get_forcis_db} \title{Download the entire FORCIS database} \usage{ -get_forcis_db(path = ".", version = NULL, overwrite = FALSE, timeout = 60) +get_forcis_db( + path = ".", + version = NULL, + check_for_update = TRUE, + overwrite = FALSE, + timeout = 60 +) } \arguments{ \item{path}{a \code{character} of length 1. The folder in which the FORCIS @@ -14,6 +20,10 @@ version number.} \item{version}{a \code{character} of length 1. The version number of the FORCIS database. Default is the latest version.} +\item{check_for_update}{a \code{logical}. If \code{TRUE} (default) it will check if a +newer version of the FORCIS database is available on Zenodo and ask user +to download it.} + \item{overwrite}{a \code{logical}. If \code{TRUE} it will override the downloaded files of the FORCIS database. Default is \code{FALSE}.}