diff --git a/R/alert_functions.R b/R/alert_functions.R index 2ceef00..f2671be 100644 --- a/R/alert_functions.R +++ b/R/alert_functions.R @@ -255,6 +255,8 @@ fouralert <- function(obj, crit, miss="last",dy=4){ #'@param dataini "notif" (default) or "sinpri" #'@param writedb TRUE if it should write into the database, default is FALSE. #'@param datasource posgreSQL connection to project's database +#'@param firstday First date of the notification series passed to getCases(). +#' Defaults to 2018-01-01. #'@return data.frame with the week condition and the number of weeks within the #'last lag weeks with conditions = TRUE. #'@examples @@ -273,7 +275,7 @@ fouralert <- function(obj, crit, miss="last",dy=4){ pipe_infodengue <- function(cities, cid10="A90", datarelatorio, finalday = Sys.Date(), iniSE = 201001, nowcasting="none", narule=NULL, writedb = FALSE, datasource = con, completetail = NA, - dataini = "notific"){ + dataini = "notific", firstday = as.Date("2018-01-01")){ if(missing(datarelatorio)) { @@ -312,7 +314,8 @@ pipe_infodengue <- function(cities, cid10="A90", datarelatorio, finalday = Sys.D message("getCli done") # Reading Cases print("Obtendo dados de notificacao ...") - casos <- getCases(cities, lastday = finalday, cid10 = cid10, type = "all", # novo + casos <- getCases(cities, lastday = finalday, firstday = firstday, + cid10 = cid10, type = "all", # novo dataini = dataini, completetail = completetail) message("getCases done") casos$inc <- casos$casos/casos$pop*100000 diff --git a/man/pipe_infodengue.Rd b/man/pipe_infodengue.Rd index 875ed50..fc0388d 100644 --- a/man/pipe_infodengue.Rd +++ b/man/pipe_infodengue.Rd @@ -15,7 +15,8 @@ pipe_infodengue( writedb = FALSE, datasource = con, completetail = NA, - dataini = "notific" + dataini = "notific", + firstday = as.Date("2018-01-01") ) } \arguments{ @@ -41,6 +42,9 @@ with zeros, "linear" for linear interpolation, "arima" for inter and extrapolati \item{dataini}{"notif" (default) or "sinpri"} +\item{firstday}{First date of the notification series passed to getCases(). +Defaults to 2018-01-01.} + \item{"bayesian"}{for the dynamic model, "none" for not doing nowcast (default)} } \value{ diff --git a/tests/testthat/test-pipe-infodengue-firstday.R b/tests/testthat/test-pipe-infodengue-firstday.R new file mode 100644 index 0000000..bdec6a8 --- /dev/null +++ b/tests/testthat/test-pipe-infodengue-firstday.R @@ -0,0 +1,41 @@ +test_that("pipe_infodengue keeps the source default and forwards an override", { + expect_identical(eval(formals(pipe_infodengue)$firstday), as.Date("2018-01-01")) + + calls <- list() + local_mocked_bindings( + read.parameters = function(cities, cid10) { + data.frame(municipio_geocodigo = cities) + }, + getClima = function(...) data.frame(), + getCases = function(cities, lastday, firstday, cid10, type, + dataini, completetail) { + calls[[length(calls) + 1L]] <<- list( + cities = cities, lastday = lastday, firstday = firstday, + cid10 = cid10, type = type, dataini = dataini, + completetail = completetail + ) + stop("captured getCases call") + }, + .package = "AlertTools" + ) + + report_end <- as.Date("2026-08-01") + expect_error(pipe_infodengue(2201919, finalday = report_end), + "captured getCases call") + expect_identical(calls[[1L]]$firstday, as.Date("2018-01-01")) + expect_identical(calls[[1L]]$lastday, report_end) + + historical_start <- as.Date("2010-01-03") + expect_error(pipe_infodengue(2201919, finalday = report_end, + firstday = historical_start), + "captured getCases call") + expect_identical(calls[[2L]]$firstday, historical_start) + expect_identical(calls[[2L]]$cid10, "A90") + expect_identical(calls[[2L]]$type, "all") + + # The original positional arguments still end at dataini. + expect_error(pipe_infodengue(2201919, "A90", 202630, report_end, + 201001, "none", NULL, FALSE, NULL, NA, + "notific"), "captured getCases call") + expect_identical(calls[[3L]]$firstday, as.Date("2018-01-01")) +})