Skip to content

Commit

Permalink
feat: add option to skip message to dl latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Feb 8, 2024
1 parent 15fc28b commit ea04835
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 33 deletions.
35 changes: 22 additions & 13 deletions R/gets.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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 ----
Expand All @@ -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 ----
Expand Down Expand Up @@ -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 ----

Expand All @@ -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 ----
Expand Down Expand Up @@ -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 ----

Expand All @@ -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 ----
Expand Down Expand Up @@ -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 ----

Expand All @@ -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 ----
Expand Down Expand Up @@ -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 ----

Expand All @@ -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 ----
Expand Down Expand Up @@ -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 ----

Expand All @@ -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 ----
Expand Down
36 changes: 20 additions & 16 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
}
}
}

Expand Down
30 changes: 27 additions & 3 deletions man/get_data.Rd

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

12 changes: 11 additions & 1 deletion man/get_forcis_db.Rd

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

0 comments on commit ea04835

Please sign in to comment.