From 9685bc0cfbf654d3298d3ed5340862eb143f421d Mon Sep 17 00:00:00 2001 From: Nicolas Casajus Date: Thu, 8 Feb 2024 10:32:11 +0100 Subject: [PATCH] feat: handle newer version - fix #31 --- R/utils.R | 44 +++++++++++++++++++++++++++++++++++++++++--- R/versions.R | 4 +--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/R/utils.R b/R/utils.R index 4c72089..3997cc9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -199,12 +199,17 @@ set_zen_version <- function(version) { check_zen_version(version) - versions <- zen_list_versions() + versions <- zen_list_versions() + latest_version <- get_zen_latest_version() if (is.null(version)) { - version <- versions[which.max(as.Date(versions$"publication_date")), - "version"] + version <- get_in_use_version() + + if (is.null(version)) { + + version <- latest_version + } } else { @@ -215,5 +220,38 @@ 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 + } + } + + set_in_use_version(version) + version } + + + +#' Get Zenodo latest version +#' +#' @noRd + +get_zen_latest_version <- function() { + + versions <- zen_list_versions() + + versions[which.max(as.Date(versions$"publication_date")), "version"] +} diff --git a/R/versions.R b/R/versions.R index 858eab0..dc41be0 100644 --- a/R/versions.R +++ b/R/versions.R @@ -23,9 +23,7 @@ get_in_use_version <- function() { #' #' @noRd -set_in_use_version <- function(version = NULL) { - - version <- set_zen_version(version) +set_in_use_version <- function(version) { saved_version <- get_in_use_version()