Skip to content

Commit 1c55ae2

Browse files
authored
Merge pull request #62 from cmu-delphi/ds/doc2
refactor(run.R)+doc(README): only read env vars
2 parents bd5daa0 + dc9ed59 commit 1c55ae2

File tree

2 files changed

+22
-68
lines changed

2 files changed

+22
-68
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@ The repo is also structured as an R package, which means that it is easy to shar
1010
# Install renv and R dependencies.
1111
make install
1212

13-
# Run the pipeline wrapper run.R.
14-
make run
15-
```
16-
17-
## Development
18-
19-
### Sample `.Renviron` Settings
20-
21-
```sh
13+
# Set your .Renviron settings.
2214
EPIDATR_USE_CACHE=true
2315
DEBUG_MODE=true
2416
USE_SHINY=false
2517
TAR_PROJECT=covid_hosp_explore
18+
EXTERNAL_SCORES_PATH=
19+
20+
# Run the pipeline wrapper run.R.
21+
make run
2622
```
2723

24+
- `EPIDATR_USE_CACHE` controls whether `epidatr` functions use the cache.
25+
- `DEBUG_MODE` controls whether `targets::tar_make` is run with the `callr_function=NULL`, which allows for debugging.
26+
- `USE_SHINY` controls whether we start a Shiny server after producing the targets.
27+
- `TAR_PROJECT` controls which `targets` project is run by `run.R`.
28+
- `EXTERNAL_SCORES_PATH` controls where external scores are loaded from. If not set, external scores are not used.
29+
30+
## Development
31+
2832
### Directory Layout
2933

3034
- `run.R` and `Makefile`: the main entrypoint for all pipelines

run.R

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -26,65 +26,15 @@
2626
# saveRDS(scorecards, "exploration-scorecards-2023-10-04.RDS")
2727

2828
print("Reading environment variables (TAR_PROJECT, EXTERNAL_SCORES_PATH, DEBUG_MODE, USE_SHINY)...")
29-
tar_project <- Sys.getenv("TAR_PROJECT", "")
29+
tar_project <- Sys.getenv("TAR_PROJECT", "covid_hosp_explore")
3030
external_scores_path <- Sys.getenv("EXTERNAL_SCORES_PATH", "")
31-
debug_mode <- Sys.getenv("DEBUG_MODE", "")
32-
use_shiny <- Sys.getenv("USE_SHINY", "")
31+
debug_mode <- as.logical(Sys.getenv("DEBUG_MODE", TRUE))
32+
use_shiny <- as.logical(Sys.getenv("USE_SHINY", FALSE))
3333

34-
readline_wrapper <- function(msg) {
35-
if (interactive()) {
36-
txt <- readline(msg)
37-
} else {
38-
cat(msg)
39-
txt <- readLines("stdin", n = 1)
40-
}
41-
return(txt)
42-
}
43-
if (tar_project == "") {
44-
project_selection <- readline_wrapper("Which project would you like to run?
45-
1: covid_hosp_explore
46-
2: flu_hosp_explore
47-
3: covid_hosp_prod
48-
4: flu_hosp_prod
49-
Input: ")
50-
tar_project <- switch(as.character(project_selection),
51-
"1" = "covid_hosp_explore",
52-
"2" = "flu_hosp_explore",
53-
"3" = "covid_hosp_prod",
54-
"4" = "flu_hosp_prod",
55-
# else
56-
stop("selection `", project_selection, "` is invalid")
57-
)
58-
} else {
59-
cat("Using project: ", tar_project, "\n")
60-
}
61-
Sys.setenv(TAR_PROJECT = tar_project)
62-
63-
64-
if (external_scores_path == "") {
65-
external_scores_path <- readline_wrapper("Path to RDS file containing external forecast scores, if desired:")
66-
} else {
67-
cat("Using external scores from ", external_scores_path, "\n")
68-
}
69-
Sys.setenv(EXTERNAL_SCORES_PATH = external_scores_path)
70-
71-
if (debug_mode == "") {
72-
debug_mode <- readline_wrapper("Would you like to run debug mode? (y/[N]): ")
73-
} else {
74-
cat("Debug mode: ", debug_mode, "\n")
75-
if (as.logical(debug_mode)) {
76-
debug_mode <- "y"
77-
}
78-
}
79-
80-
if (use_shiny == "") {
81-
use_shiny <- readline_wrapper("Would you like to run the shiny app? (y/[N]): ")
82-
} else {
83-
cat("Use shiny: ", use_shiny, "\n")
84-
if (as.logical(use_shiny)) {
85-
use_shiny <- "y"
86-
}
87-
}
34+
cat("Using project: ", tar_project, "\n")
35+
if (external_scores_path != "") cat("Using external scores from ", external_scores_path, "\n")
36+
if (debug_mode) cat("Debug mode is on.")
37+
if (use_shiny) cat("Running shiny server after results.")
8838

8939

9040
suppressPackageStartupMessages({
@@ -97,15 +47,15 @@ store_dir <- tar_path_store()
9747
if (!dir.exists(store_dir)) dir.create(store_dir)
9848

9949
tar_manifest()
100-
if (debug_mode == "y") {
50+
if (debug_mode) {
10151
tar_make(callr_function = NULL)
10252
} else {
10353
tar_make()
10454
}
10555
# tar_make_clustermq(workers = 2) # nolint
10656
# tar_make_future(workers = 2) # nolint
10757

108-
if (use_shiny == "y") {
58+
if (use_shiny) {
10959
# Prevent functions defined in /R dir from being loaded unnecessarily
11060
options(shiny.autoload.r = FALSE)
11161

0 commit comments

Comments
 (0)