From 2a626c79239889d72c8363378923aeca55d66ac3 Mon Sep 17 00:00:00 2001 From: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:26:57 +0000 Subject: [PATCH] Make argument defaults explicit where possible (#729) * Make argument defaults explicit where possible * Run devtools::document() * Add NEWS item --- NEWS.md | 1 + R/epinow.R | 6 +----- R/regional_epinow.R | 3 +-- R/summarise.R | 9 ++------- R/utilities.R | 5 +---- man/clean_nowcasts.Rd | 2 +- man/epinow.Rd | 2 +- man/regional_epinow.Rd | 2 +- man/regional_summary.Rd | 2 +- man/summarise_results.Rd | 2 +- 10 files changed, 11 insertions(+), 23 deletions(-) diff --git a/NEWS.md b/NEWS.md index cceaa763e..cadaacf45 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ## Documentation +- Some implicit argument defaults have been made explicit in the function definition. By @Bisaloo in #729. - The installation guide in the README has been updated to provide instructions for configuring the C toolchain of Windows, MacOS, and Linux. By @jamesmbaazam in #707 and reviewed by @sbfnk. ## Model changes diff --git a/R/epinow.R b/R/epinow.R index c4d4c7b70..5baa06093 100644 --- a/R/epinow.R +++ b/R/epinow.R @@ -92,7 +92,7 @@ epinow <- function(data, CrIs = c(0.2, 0.5, 0.9), filter_leading_zeros = TRUE, zero_threshold = Inf, - return_output = FALSE, + return_output = is.null(target_folder), output = c("samples", "plots", "latest", "fit", "timing"), plot_args = list(), target_folder = NULL, target_date, @@ -116,10 +116,6 @@ epinow <- function(data, assert_string(id) assert_logical(verbose) - if (is.null(target_folder)) { - return_output <- TRUE - } - if (is.null(CrIs) || length(CrIs) == 0 || !is.numeric(CrIs)) { futile.logger::flog.fatal( "At least one credible interval must be specified", diff --git a/R/regional_epinow.R b/R/regional_epinow.R index e43471c4b..80408d0ca 100644 --- a/R/regional_epinow.R +++ b/R/regional_epinow.R @@ -108,7 +108,7 @@ regional_epinow <- function(data, "regions", "summary", "samples", "plots", "latest" ), - return_output = FALSE, + return_output = is.null(target_folder), summary_args = list(), verbose = FALSE, logs = tempdir(check = TRUE), ..., @@ -148,7 +148,6 @@ regional_epinow <- function(data, futile.logger::flog.info( "No target directory specified so returning output" ) - return_output <- TRUE } else { futile.logger::flog.info("Saving estimates to : %s", target_folder) } diff --git a/R/summarise.R b/R/summarise.R index 86299cc01..b340d4ba4 100644 --- a/R/summarise.R +++ b/R/summarise.R @@ -26,12 +26,8 @@ summarise_results <- function(regions, summaries = NULL, results_dir = NULL, - target_date = NULL, + target_date = "latest", region_scale = "Region") { - if (is.null(target_date)) { - target_date <- "latest" - } - if (is.null(results_dir)) { if (is.null(summaries)) { stop( @@ -181,7 +177,7 @@ regional_summary <- function(regional_output = NULL, target_date = NULL, region_scale = "Region", all_regions = TRUE, - return_output = FALSE, + return_output = is.null(summary_dir), plot = TRUE, max_plot = 10, ...) { @@ -190,7 +186,6 @@ regional_summary <- function(regional_output = NULL, futile.logger::flog.info( "No summary directory specified so returning summary output" ) - return_output <- TRUE } else { futile.logger::flog.info("Saving summary to : %s", summary_dir) } diff --git a/R/utilities.R b/R/utilities.R index 54177c107..e3a719b57 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -13,10 +13,7 @@ #' @importFrom futile.logger flog.info #' @return No return value, called for side effects #' @export -clean_nowcasts <- function(date = NULL, nowcast_dir = ".") { - if (is.null(date)) { - date <- Sys.Date() - } +clean_nowcasts <- function(date = Sys.Date(), nowcast_dir = ".") { dirs <- list.dirs(nowcast_dir, recursive = FALSE) purrr::walk( dirs, diff --git a/man/clean_nowcasts.Rd b/man/clean_nowcasts.Rd index 95903e262..83dec7576 100644 --- a/man/clean_nowcasts.Rd +++ b/man/clean_nowcasts.Rd @@ -4,7 +4,7 @@ \alias{clean_nowcasts} \title{Clean Nowcasts for a Supplied Date} \usage{ -clean_nowcasts(date = NULL, nowcast_dir = ".") +clean_nowcasts(date = Sys.Date(), nowcast_dir = ".") } \arguments{ \item{date}{Date object. Defaults to today's date} diff --git a/man/epinow.Rd b/man/epinow.Rd index 1545f5703..fd9b70b3c 100644 --- a/man/epinow.Rd +++ b/man/epinow.Rd @@ -18,7 +18,7 @@ epinow( CrIs = c(0.2, 0.5, 0.9), filter_leading_zeros = TRUE, zero_threshold = Inf, - return_output = FALSE, + return_output = is.null(target_folder), output = c("samples", "plots", "latest", "fit", "timing"), plot_args = list(), target_folder = NULL, diff --git a/man/regional_epinow.Rd b/man/regional_epinow.Rd index 5106c9a39..ea6134a86 100644 --- a/man/regional_epinow.Rd +++ b/man/regional_epinow.Rd @@ -20,7 +20,7 @@ regional_epinow( target_date, non_zero_points = 2, output = c("regions", "summary", "samples", "plots", "latest"), - return_output = FALSE, + return_output = is.null(target_folder), summary_args = list(), verbose = FALSE, logs = tempdir(check = TRUE), diff --git a/man/regional_summary.Rd b/man/regional_summary.Rd index 727735a9e..83ce911db 100644 --- a/man/regional_summary.Rd +++ b/man/regional_summary.Rd @@ -12,7 +12,7 @@ regional_summary( target_date = NULL, region_scale = "Region", all_regions = TRUE, - return_output = FALSE, + return_output = is.null(summary_dir), plot = TRUE, max_plot = 10, ... diff --git a/man/summarise_results.Rd b/man/summarise_results.Rd index d621752e9..1a303d04e 100644 --- a/man/summarise_results.Rd +++ b/man/summarise_results.Rd @@ -8,7 +8,7 @@ summarise_results( regions, summaries = NULL, results_dir = NULL, - target_date = NULL, + target_date = "latest", region_scale = "Region" ) }