Skip to content

Commit 3d17bbf

Browse files
committed
forecast for [2025-02-12], r4.4.2, epiproc 0.10.5
1 parent afc0fe1 commit 3d17bbf

8 files changed

+8474
-1925
lines changed

R/aux_data_utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ daily_to_weekly_archive <- function(epi_arch,
194194
day_of_week = 4L,
195195
day_of_week_end = 7L) {
196196
agg_method <- arg_match(agg_method)
197-
keys <- key_colnames(epi_arch, exclude = "time_value")
197+
keys <- key_colnames(epi_arch, exclude = c("time_value", "version"))
198198
ref_time_values <- epi_arch$DT$version %>%
199199
unique() %>%
200200
sort()

R/utils.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ get_exclusions <- function(
156156

157157
data_substitutions <- function(dataset, disease, forecast_generation_date) {
158158
disease <- "flu"
159-
forecast_generation_date <- as.Date("2025-01-08")
160159
substitutions <- readr::read_csv(
161160
glue::glue("{disease}_data_substitutions.csv"),
162161
comment = "#",

flu_data_substitutions.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
geo_value, forecast_date, time_value, value
22
sd, 2025-01-08, 2025-01-01, 33
33
id, 2025-01-08, 2025-01-01, 323
4+
az, 2025-02-12, 2025-02-05, 850
5+
de, 2025-02-12, 2025-02-05, 130
6+
id, 2025-02-12, 2025-02-05, 150
7+
nm, 2025-02-12, 2025-02-05, 200
8+
ca, 2025-02-12, 2025-02-05, 3893
9+
ms, 2025-02-12, 2025-02-05, 420
10+
ok, 2025-02-12, 2025-02-05, 850

renv.lock

Lines changed: 8360 additions & 1824 deletions
Large diffs are not rendered by default.

renv/activate.R

Lines changed: 102 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
local({
33

44
# the requested version of renv
5-
version <- "1.0.11"
5+
version <- "1.1.1"
66
attr(version, "sha") <- NULL
77

88
# the project directory
@@ -42,7 +42,7 @@ local({
4242
return(FALSE)
4343

4444
# next, check environment variables
45-
# TODO: prefer using the configuration one in the future
45+
# prefer using the configuration one in the future
4646
envvars <- c(
4747
"RENV_CONFIG_AUTOLOADER_ENABLED",
4848
"RENV_AUTOLOADER_ENABLED",
@@ -135,12 +135,12 @@ local({
135135

136136
# R help links
137137
pattern <- "`\\?(renv::(?:[^`])+)`"
138-
replacement <- "`\033]8;;ide:help:\\1\a?\\1\033]8;;\a`"
138+
replacement <- "`\033]8;;x-r-help:\\1\a?\\1\033]8;;\a`"
139139
text <- gsub(pattern, replacement, text, perl = TRUE)
140140

141141
# runnable code
142142
pattern <- "`(renv::(?:[^`])+)`"
143-
replacement <- "`\033]8;;ide:run:\\1\a\\1\033]8;;\a`"
143+
replacement <- "`\033]8;;x-r-run:\\1\a\\1\033]8;;\a`"
144144
text <- gsub(pattern, replacement, text, perl = TRUE)
145145

146146
# return ansified text
@@ -209,10 +209,6 @@ local({
209209

210210
}
211211

212-
startswith <- function(string, prefix) {
213-
substring(string, 1, nchar(prefix)) == prefix
214-
}
215-
216212
bootstrap <- function(version, library) {
217213

218214
friendly <- renv_bootstrap_version_friendly(version)
@@ -563,6 +559,9 @@ local({
563559

564560
# prepare download options
565561
token <- renv_bootstrap_github_token()
562+
if (is.null(token))
563+
token <- ""
564+
566565
if (nzchar(Sys.which("curl")) && nzchar(token)) {
567566
fmt <- "--location --fail --header \"Authorization: token %s\""
568567
extra <- sprintf(fmt, token)
@@ -951,8 +950,14 @@ local({
951950
}
952951

953952
renv_bootstrap_validate_version_dev <- function(version, description) {
953+
954954
expected <- description[["RemoteSha"]]
955-
is.character(expected) && startswith(expected, version)
955+
if (!is.character(expected))
956+
return(FALSE)
957+
958+
pattern <- sprintf("^\\Q%s\\E", version)
959+
grepl(pattern, expected, perl = TRUE)
960+
956961
}
957962

958963
renv_bootstrap_validate_version_release <- function(version, description) {
@@ -1132,10 +1137,10 @@ local({
11321137

11331138
renv_bootstrap_exec <- function(project, libpath, version) {
11341139
if (!renv_bootstrap_load(project, libpath, version))
1135-
renv_bootstrap_run(version, libpath)
1140+
renv_bootstrap_run(project, libpath, version)
11361141
}
11371142

1138-
renv_bootstrap_run <- function(version, libpath) {
1143+
renv_bootstrap_run <- function(project, libpath, version) {
11391144

11401145
# perform bootstrap
11411146
bootstrap(version, libpath)
@@ -1146,7 +1151,7 @@ local({
11461151

11471152
# try again to load
11481153
if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) {
1149-
return(renv::load(project = getwd()))
1154+
return(renv::load(project = project))
11501155
}
11511156

11521157
# failed to download or load renv; warn the user
@@ -1192,98 +1197,101 @@ local({
11921197
jsonlite::fromJSON(txt = text, simplifyVector = FALSE)
11931198
}
11941199

1195-
renv_json_read_default <- function(file = NULL, text = NULL) {
1196-
1197-
# find strings in the JSON
1198-
text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n")
1199-
pattern <- '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
1200-
locs <- gregexpr(pattern, text, perl = TRUE)[[1]]
1201-
1202-
# if any are found, replace them with placeholders
1203-
replaced <- text
1204-
strings <- character()
1205-
replacements <- character()
1206-
1207-
if (!identical(c(locs), -1L)) {
1208-
1209-
# get the string values
1210-
starts <- locs
1211-
ends <- locs + attr(locs, "match.length") - 1L
1212-
strings <- substring(text, starts, ends)
1213-
1214-
# only keep those requiring escaping
1215-
strings <- grep("[[\\]{}:]", strings, perl = TRUE, value = TRUE)
1216-
1217-
# compute replacements
1218-
replacements <- sprintf('"\032%i\032"', seq_along(strings))
1219-
1220-
# replace the strings
1221-
mapply(function(string, replacement) {
1222-
replaced <<- sub(string, replacement, replaced, fixed = TRUE)
1223-
}, strings, replacements)
1200+
renv_json_read_patterns <- function() {
1201+
1202+
list(
1203+
1204+
# objects
1205+
list("{", "\t\n\tobject(\t\n\t"),
1206+
list("}", "\t\n\t)\t\n\t"),
1207+
1208+
# arrays
1209+
list("[", "\t\n\tarray(\t\n\t"),
1210+
list("]", "\n\t\n)\n\t\n"),
1211+
1212+
# maps
1213+
list(":", "\t\n\t=\t\n\t")
1214+
1215+
)
1216+
1217+
}
12241218

1219+
renv_json_read_envir <- function() {
1220+
1221+
envir <- new.env(parent = emptyenv())
1222+
1223+
envir[["+"]] <- `+`
1224+
envir[["-"]] <- `-`
1225+
1226+
envir[["object"]] <- function(...) {
1227+
result <- list(...)
1228+
names(result) <- as.character(names(result))
1229+
result
12251230
}
1226-
1227-
# transform the JSON into something the R parser understands
1228-
transformed <- replaced
1229-
transformed <- gsub("{}", "`names<-`(list(), character())", transformed, fixed = TRUE)
1230-
transformed <- gsub("[[{]", "list(", transformed, perl = TRUE)
1231-
transformed <- gsub("[]}]", ")", transformed, perl = TRUE)
1232-
transformed <- gsub(":", "=", transformed, fixed = TRUE)
1233-
text <- paste(transformed, collapse = "\n")
1234-
1235-
# parse it
1236-
json <- parse(text = text, keep.source = FALSE, srcfile = NULL)[[1L]]
1237-
1238-
# construct map between source strings, replaced strings
1239-
map <- as.character(parse(text = strings))
1240-
names(map) <- as.character(parse(text = replacements))
1241-
1242-
# convert to list
1243-
map <- as.list(map)
1244-
1245-
# remap strings in object
1246-
remapped <- renv_json_read_remap(json, map)
1247-
1248-
# evaluate
1249-
eval(remapped, envir = baseenv())
1250-
1231+
1232+
envir[["array"]] <- list
1233+
1234+
envir[["true"]] <- TRUE
1235+
envir[["false"]] <- FALSE
1236+
envir[["null"]] <- NULL
1237+
1238+
envir
1239+
12511240
}
12521241

1253-
renv_json_read_remap <- function(json, map) {
1254-
1255-
# fix names
1256-
if (!is.null(names(json))) {
1257-
lhs <- match(names(json), names(map), nomatch = 0L)
1258-
rhs <- match(names(map), names(json), nomatch = 0L)
1259-
names(json)[rhs] <- map[lhs]
1242+
renv_json_read_remap <- function(object, patterns) {
1243+
1244+
# repair names if necessary
1245+
if (!is.null(names(object))) {
1246+
1247+
nms <- names(object)
1248+
for (pattern in patterns)
1249+
nms <- gsub(pattern[[2L]], pattern[[1L]], nms, fixed = TRUE)
1250+
names(object) <- nms
1251+
12601252
}
1261-
1262-
# fix values
1263-
if (is.character(json))
1264-
return(map[[json]] %||% json)
1265-
1266-
# handle true, false, null
1267-
if (is.name(json)) {
1268-
text <- as.character(json)
1269-
if (text == "true")
1270-
return(TRUE)
1271-
else if (text == "false")
1272-
return(FALSE)
1273-
else if (text == "null")
1274-
return(NULL)
1253+
1254+
# repair strings if necessary
1255+
if (is.character(object)) {
1256+
for (pattern in patterns)
1257+
object <- gsub(pattern[[2L]], pattern[[1L]], object, fixed = TRUE)
12751258
}
1259+
1260+
# recurse for other objects
1261+
if (is.recursive(object))
1262+
for (i in seq_along(object))
1263+
object[i] <- list(renv_json_read_remap(object[[i]], patterns))
1264+
1265+
# return remapped object
1266+
object
1267+
1268+
}
12761269

1277-
# recurse
1278-
if (is.recursive(json)) {
1279-
for (i in seq_along(json)) {
1280-
json[i] <- list(renv_json_read_remap(json[[i]], map))
1281-
}
1282-
}
1270+
renv_json_read_default <- function(file = NULL, text = NULL) {
12831271

1284-
json
1272+
# read json text
1273+
text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n")
1274+
1275+
# convert into something the R parser will understand
1276+
patterns <- renv_json_read_patterns()
1277+
transformed <- text
1278+
for (pattern in patterns)
1279+
transformed <- gsub(pattern[[1L]], pattern[[2L]], transformed, fixed = TRUE)
1280+
1281+
# parse it
1282+
rfile <- tempfile("renv-json-", fileext = ".R")
1283+
on.exit(unlink(rfile), add = TRUE)
1284+
writeLines(transformed, con = rfile)
1285+
json <- parse(rfile, keep.source = FALSE, srcfile = NULL)[[1L]]
12851286

1287+
# evaluate in safe environment
1288+
result <- eval(json, envir = renv_json_read_envir())
1289+
1290+
# fix up strings if necessary
1291+
renv_json_read_remap(result, patterns)
1292+
12861293
}
1294+
12871295

12881296
# load the renv profile, if any
12891297
renv_bootstrap_profile_load(project)

scripts/covid_hosp_prod.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ rlang::list2(
150150
} else {
151151
train_data <-
152152
nhsn_latest_data %>%
153-
data_substitutions(disease = "covid") %>%
153+
data_substitutions(disease = "covid", forecast_generation_date) %>%
154154
as_epi_df(as_of = as.Date(forecast_date_int)) %>%
155155
mutate(time_value = time_value - 3)
156156
}
@@ -195,7 +195,7 @@ rlang::list2(
195195
filter(geo_value %nin% geo_exclusions) %>%
196196
ungroup() %>%
197197
bind_rows(forecast_res %>%
198-
filter(forecaster %in% c("windowed_seasonal", "windowed_seasonal_extra_sources")) %>%
198+
filter(forecaster %in% c("windowed_seasonal_extra_sources")) %>%
199199
filter(forecast_date < target_end_date)) %>% # don't use for neg aheads
200200
group_by(geo_value, forecast_date, target_end_date, quantile) %>%
201201
summarize(value = mean(value, na.rm = TRUE), .groups = "drop") %>%

scripts/flu_hosp_prod.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ rlang::list2(
146146
) %>%
147147
filter(version == max(version)) %>%
148148
select(-version) %>%
149-
data_substitutions(disease = "flu") %>%
149+
data_substitutions(disease = "flu", forecast_generation_date) %>%
150150
as_epi_df(other_keys = "source", as_of = Sys.Date())
151151
most_recent_result
152152
},
@@ -397,7 +397,6 @@ rlang::list2(
397397
tar_target(
398398
name = truth_data,
399399
command = {
400-
browser()
401400
date <- forecast_generation_date_int
402401
nssp_state <-
403402
current_nssp_archive %>%

scripts/targets-exploration-common.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ make_historical_flu_data_targets <- function() {
338338
add_season_info() %>%
339339
mutate(agg_level = ifelse(grepl("[0-9]{2}", geo_value), "hhs_region", ifelse("us" == geo_value, "nation", "state"))) %>%
340340
add_pop_and_density() %>%
341-
mutate(hhs = hhs / population * 10L^5) %>%
341+
mutate(hhs = hhs_7dsum / population * 10L^5) %>%
342342
mutate(source = "nhsn") %>%
343343
mutate(agg_level = ifelse(geo_value == "us", "nation", "state")) %>%
344344
as_epi_archive(other_keys = "source", compactify = TRUE) %>%

0 commit comments

Comments
 (0)