Skip to content

Commit

Permalink
updating figures
Browse files Browse the repository at this point in the history
  • Loading branch information
lucy-gf committed Nov 21, 2024
1 parent d52fd20 commit 30b1891
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 48 deletions.
37 changes: 19 additions & 18 deletions inst/analysis/renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Packages": {
"MASS": {
"Package": "MASS",
"Version": "7.3-58.2",
"Version": "7.3-60.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -22,23 +22,24 @@
"stats",
"utils"
],
"Hash": "e02d1a0f6122fd3e634b25b433704344"
"Hash": "2f342c46163b0b54d7b64d1f798e2c78"
},
"Matrix": {
"Package": "Matrix",
"Version": "1.5-3",
"Version": "1.7-1",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"grDevices",
"graphics",
"grid",
"lattice",
"methods",
"stats",
"utils"
],
"Hash": "4006dffe49958d2dd591c17e61e60591"
"Hash": "5122bb14d8736372411f955e1b16bc8a"
},
"R6": {
"Package": "R6",
Expand Down Expand Up @@ -181,13 +182,13 @@
},
"dotCall64": {
"Package": "dotCall64",
"Version": "1.1-1",
"Version": "1.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "80f374ef8500fcdc5d84a0345b837227"
"Hash": "7339da8bc231184ec506d7d144776b2a"
},
"fansi": {
"Package": "fansi",
Expand All @@ -210,7 +211,7 @@
},
"fields": {
"Package": "fields",
"Version": "16.2",
"Version": "16.3",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -220,7 +221,7 @@
"spam",
"viridisLite"
],
"Hash": "dac9b7c0f2450644021e2097a5360c12"
"Hash": "2900d13ae2ee1dcf9f9cce088103667c"
},
"generics": {
"Package": "generics",
Expand Down Expand Up @@ -452,7 +453,7 @@
},
"nlme": {
"Package": "nlme",
"Version": "3.1-165",
"Version": "3.1-164",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -462,7 +463,7 @@
"stats",
"utils"
],
"Hash": "2769a88be217841b1f33ed469675c3cc"
"Hash": "a623a2239e642806158bc4dc3f51565d"
},
"oai": {
"Package": "oai",
Expand All @@ -480,9 +481,9 @@
},
"odin": {
"Package": "odin",
"Version": "1.2.6",
"Version": "1.2.5",
"Source": "Repository",
"Repository": "CRAN",
"Repository": "RSPM",
"Requirements": [
"R6",
"cinterpolate",
Expand All @@ -493,7 +494,7 @@
"ring",
"withr"
],
"Hash": "9f16ddb7672f4d2b4aa796cfb066b141"
"Hash": "28f2759ad947425cf50aa0069b5a2f57"
},
"openssl": {
"Package": "openssl",
Expand All @@ -514,7 +515,7 @@
"RemoteUsername": "cmmid",
"RemoteRepo": "paramix",
"RemoteRef": "main",
"RemoteSha": "f67557c943c3111027d12d84d457d408431cde54",
"RemoteSha": "7d5e46f5afe942a94bd8486c5f1dc48756163261",
"Requirements": [
"R",
"data.table"
Expand Down Expand Up @@ -579,13 +580,13 @@
},
"renv": {
"Package": "renv",
"Version": "1.0.7",
"Version": "1.0.11",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"utils"
],
"Hash": "397b7b2a265bc5a7a06852524dabae20"
"Hash": "47623f66b4e80b3b0587bc5d7b309888"
},
"ring": {
"Package": "ring",
Expand Down Expand Up @@ -652,7 +653,7 @@
},
"spam": {
"Package": "spam",
"Version": "2.10-0",
"Version": "2.11-0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
Expand All @@ -662,7 +663,7 @@
"grid",
"methods"
],
"Hash": "ffe1f9e95a4375530747b268f82b5086"
"Hash": "6581c0a0bb8594b85c8de869644174ac"
},
"stringi": {
"Package": "stringi",
Expand Down
105 changes: 95 additions & 10 deletions inst/analysis/renv/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local({

# the requested version of renv
version <- "1.0.7"
version <- "1.0.11"
attr(version, "sha") <- NULL

# the project directory
Expand Down Expand Up @@ -98,6 +98,66 @@ local({
unloadNamespace("renv")

# load bootstrap tools
ansify <- function(text) {
if (renv_ansify_enabled())
renv_ansify_enhanced(text)
else
renv_ansify_default(text)
}

renv_ansify_enabled <- function() {

override <- Sys.getenv("RENV_ANSIFY_ENABLED", unset = NA)
if (!is.na(override))
return(as.logical(override))

pane <- Sys.getenv("RSTUDIO_CHILD_PROCESS_PANE", unset = NA)
if (identical(pane, "build"))
return(FALSE)

testthat <- Sys.getenv("TESTTHAT", unset = "false")
if (tolower(testthat) %in% "true")
return(FALSE)

iderun <- Sys.getenv("R_CLI_HAS_HYPERLINK_IDE_RUN", unset = "false")
if (tolower(iderun) %in% "false")
return(FALSE)

TRUE

}

renv_ansify_default <- function(text) {
text
}

renv_ansify_enhanced <- function(text) {

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

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

# return ansified text
text

}

renv_ansify_init <- function() {

envir <- renv_envir_self()
if (renv_ansify_enabled())
assign("ansify", renv_ansify_enhanced, envir = envir)
else
assign("ansify", renv_ansify_default, envir = envir)

}

`%||%` <- function(x, y) {
if (is.null(x)) y else x
}
Expand Down Expand Up @@ -142,7 +202,10 @@ local({
# compute common indent
indent <- regexpr("[^[:space:]]", lines)
common <- min(setdiff(indent, -1L)) - leave
paste(substring(lines, common), collapse = "\n")
text <- paste(substring(lines, common), collapse = "\n")

# substitute in ANSI links for executable renv code
ansify(text)

}

Expand Down Expand Up @@ -305,8 +368,11 @@ local({
quiet = TRUE
)

if ("headers" %in% names(formals(utils::download.file)))
args$headers <- renv_bootstrap_download_custom_headers(url)
if ("headers" %in% names(formals(utils::download.file))) {
headers <- renv_bootstrap_download_custom_headers(url)
if (length(headers) && is.character(headers))
args$headers <- headers
}

do.call(utils::download.file, args)

Expand Down Expand Up @@ -385,10 +451,21 @@ local({
for (type in types) {
for (repos in renv_bootstrap_repos()) {

# build arguments for utils::available.packages() call
args <- list(type = type, repos = repos)

# add custom headers if available -- note that
# utils::available.packages() will pass this to download.file()
if ("headers" %in% names(formals(utils::download.file))) {
headers <- renv_bootstrap_download_custom_headers(repos)
if (length(headers) && is.character(headers))
args$headers <- headers
}

# retrieve package database
db <- tryCatch(
as.data.frame(
utils::available.packages(type = type, repos = repos),
do.call(utils::available.packages, args),
stringsAsFactors = FALSE
),
error = identity
Expand Down Expand Up @@ -470,23 +547,31 @@ local({

}

renv_bootstrap_github_token <- function() {
for (envvar in c("GITHUB_TOKEN", "GITHUB_PAT", "GH_TOKEN")) {
envval <- Sys.getenv(envvar, unset = NA)
if (!is.na(envval))
return(envval)
}
}

renv_bootstrap_download_github <- function(version) {

enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE")
if (!identical(enabled, "TRUE"))
return(FALSE)

# prepare download options
pat <- Sys.getenv("GITHUB_PAT")
if (nzchar(Sys.which("curl")) && nzchar(pat)) {
token <- renv_bootstrap_github_token()
if (nzchar(Sys.which("curl")) && nzchar(token)) {
fmt <- "--location --fail --header \"Authorization: token %s\""
extra <- sprintf(fmt, pat)
extra <- sprintf(fmt, token)
saved <- options("download.file.method", "download.file.extra")
options(download.file.method = "curl", download.file.extra = extra)
on.exit(do.call(base::options, saved), add = TRUE)
} else if (nzchar(Sys.which("wget")) && nzchar(pat)) {
} else if (nzchar(Sys.which("wget")) && nzchar(token)) {
fmt <- "--header=\"Authorization: token %s\""
extra <- sprintf(fmt, pat)
extra <- sprintf(fmt, token)
saved <- options("download.file.method", "download.file.extra")
options(download.file.method = "wget", download.file.extra = extra)
on.exit(do.call(base::options, saved), add = TRUE)
Expand Down
11 changes: 5 additions & 6 deletions inst/analysis/scripts/fig_averted.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ int_dt <- ts_dt[intervention != "none", .(
int_dt[, averted_death := i.deaths - deaths]

int_dt$method <- factor(int_dt$method, levels=unique(int_dt$method))
int_dt$intervention <- factor(int_dt$intervention, levels=unique(int_dt$intervention))

# in this model, deaths do not affect dynamics, so the method for aggregating
# death parameter (`method` field) is irrelevant
p <- ggplot(int_dt) + aes(
x = method, y = 1000*averted_death/capita, fill = intervention
p <- ggplot(int_dt[!method=='mean_f']) + aes(
x = intervention, y = 1000*averted_death/capita, fill = method
) +
facet_nested(place ~ pathogen, scale = "free_y", labeller = labeller(
pathogen = pathogen_labels, place = iso_labels
Expand All @@ -41,10 +42,8 @@ p <- ggplot(int_dt) + aes(
element_text(size = 16), legend.position = "right",
panel.spacing.x = unit(1.5, "line")
) +
scale_x_discrete("Aggregation assumption", labels = model_assumption_labels) +
scale_x_discrete("Vaccination age group", labels = intervention_labels) +
scale_y_continuous("Deaths averted (per 1000)") +
scale_color_intervention(
breaks = rev(names(intervention_labels)) # order by ranking
)
scale_color_model()

ggsave(tail(.args, 1), p, width = 25, height = 14, units = "cm", bg = "white")
6 changes: 3 additions & 3 deletions inst/analysis/scripts/fig_fullsummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ifr_dt <- bound_pop_dt[,
by = iso3
]

ifr_p <- ggplot(ifr_dt[x <= 100]) + aes(x, y = value, color = method) +
ifr_p <- ggplot(ifr_dt[x <= 100 & !method=='mean_f']) + aes(x, y = value, color = method) +
facet_iso(rows = vars(pathogen), labeller = labeller(
iso3 = iso_labels, pathogen = pathogen_labels
)) +
Expand Down Expand Up @@ -99,8 +99,8 @@ inc_p <- ggplot(inc_dt[between(time, 0, 7*15)]) + aes(
)


summary_p <- pop_p + lex_p + ifr_p + inc_p + plot_layout(
ncol = 1, heights = c(1, 1, 2, 1)
summary_p <- pop_p + ifr_p + inc_p + plot_layout(
ncol = 1, heights = c(1, 2, 1)
) + plot_annotation(tag_levels = 'a', tag_prefix = '(',
tag_suffix = ') ')

Expand Down
Loading

0 comments on commit 30b1891

Please sign in to comment.