Skip to content

Commit c775304

Browse files
authored
Merge pull request #69 from cmu-delphi/ds/aws-s3
feat: add s3 sync option for targets
2 parents 6d1ca2a + 16a109f commit c775304

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ DEBUG_MODE=true
1616
USE_SHINY=false
1717
TAR_PROJECT=covid_hosp_explore
1818
EXTERNAL_SCORES_PATH=
19+
USE_AWS_S3=false
20+
AWS_S3_PREFIX=
1921

2022
# Run the pipeline wrapper run.R.
2123
make run
@@ -26,6 +28,8 @@ make run
2628
- `USE_SHINY` controls whether we start a Shiny server after producing the targets.
2729
- `TAR_PROJECT` controls which `targets` project is run by `run.R`.
2830
- `EXTERNAL_SCORES_PATH` controls where external scores are loaded from. If not set, external scores are not used.
31+
- `USE_AWS_S3` controls whether we use AWS S3 to store the cache.
32+
- `AWS_S3_PREFIX` controls the prefix to use in the AWS S3 bucket (a prefix is a pseudo-directory in a bucket).
2933

3034
## Development
3135

extras/extra-packages.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ library(fs)
33
library(glue)
44
library(languageserver)
55
library(pak)
6+
library(paws.storage)
67
library(quantreg)
78
library(renv)
89
library(rspm)

renv.lock

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@
799799
"RemoteUsername": "cmu-delphi",
800800
"RemoteRepo": "epidatr",
801801
"RemoteRef": "dev",
802-
"RemoteSha": "ee952c518ac0cf7cc25083b6c54a0b284d2c3448",
802+
"RemoteSha": "83e986b90ff48a972a2de972c184ec06bcce2113",
803803
"Requirements": [
804804
"MMWRweek",
805805
"R",
@@ -816,7 +816,7 @@
816816
"tibble",
817817
"xml2"
818818
],
819-
"Hash": "c628a40210a598e5c165e4a31c7d781b"
819+
"Hash": "a0cd96909bf0dc5d470f5ed08fb81ff7"
820820
},
821821
"epipredict": {
822822
"Package": "epipredict",
@@ -1772,6 +1772,35 @@
17721772
],
17731773
"Hash": "cbb49c720a5e4bf1fe36a870b07d1a0c"
17741774
},
1775+
"paws.common": {
1776+
"Package": "paws.common",
1777+
"Version": "0.6.4",
1778+
"Source": "Repository",
1779+
"Repository": "RSPM",
1780+
"Requirements": [
1781+
"Rcpp",
1782+
"base64enc",
1783+
"curl",
1784+
"digest",
1785+
"httr",
1786+
"jsonlite",
1787+
"methods",
1788+
"stats",
1789+
"utils",
1790+
"xml2"
1791+
],
1792+
"Hash": "fcc0e7509d0c9da0874b5d3a7d8ea904"
1793+
},
1794+
"paws.storage": {
1795+
"Package": "paws.storage",
1796+
"Version": "0.4.0",
1797+
"Source": "Repository",
1798+
"Repository": "RSPM",
1799+
"Requirements": [
1800+
"paws.common"
1801+
],
1802+
"Hash": "8aea3bee1ea38991f23aea27583b93ef"
1803+
},
17751804
"pillar": {
17761805
"Package": "pillar",
17771806
"Version": "1.9.0",
@@ -2216,14 +2245,14 @@
22162245
},
22172246
"rlang": {
22182247
"Package": "rlang",
2219-
"Version": "1.1.1",
2248+
"Version": "1.1.2",
22202249
"Source": "Repository",
2221-
"Repository": "CRAN",
2250+
"Repository": "RSPM",
22222251
"Requirements": [
22232252
"R",
22242253
"utils"
22252254
],
2226-
"Hash": "a85c767b55f0bf9b7ad16c6d7baee5bb"
2255+
"Hash": "50a6dbdc522936ca35afc5e2082ea91b"
22272256
},
22282257
"rmarkdown": {
22292258
"Package": "rmarkdown",

run.R

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# # Example fetching external scores from the forecasting bucket
1111
# library(aws.s3)
1212
#
13+
# # We recommend setting these in your user config files such as ~/.zprofile.
1314
# Sys.setenv(
1415
# AWS_ACCESS_KEY_ID = "",
1516
# AWS_SECRET_ACCESS_KEY = ""
@@ -25,17 +26,23 @@
2526
# # Save to disk
2627
# saveRDS(scorecards, "exploration-scorecards-2023-10-04.RDS")
2728

28-
print("Reading environment variables (TAR_PROJECT, EXTERNAL_SCORES_PATH, DEBUG_MODE, USE_SHINY)...")
2929
tar_project <- Sys.getenv("TAR_PROJECT", "covid_hosp_explore")
3030
external_scores_path <- Sys.getenv("EXTERNAL_SCORES_PATH", "")
3131
debug_mode <- as.logical(Sys.getenv("DEBUG_MODE", TRUE))
3232
use_shiny <- as.logical(Sys.getenv("USE_SHINY", FALSE))
33-
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.")
38-
33+
use_aws_s3 <- as.logical(Sys.getenv("USE_AWS_S3", FALSE))
34+
aws_s3_prefix <- Sys.getenv("AWS_S3_PREFIX", "exploration")
35+
cli::cli_inform(
36+
c(
37+
"i" = "Reading environment variables...",
38+
"*" = "TAR_PROJECT = {tar_project}",
39+
"*" = "EXTERNAL_SCORES_PATH = {external_scores_path}",
40+
"*" = "DEBUG_MODE = {debug_mode}",
41+
"*" = "USE_SHINY = {use_shiny}",
42+
"*" = "USE_AWS_S3 = {use_aws_s3}",
43+
"*" = "AWS_S3_PREFIX = {aws_s3_prefix}"
44+
)
45+
)
3946

4047
suppressPackageStartupMessages({
4148
library(targets)
@@ -46,6 +53,18 @@ suppressPackageStartupMessages({
4653
store_dir <- tar_path_store()
4754
if (!dir.exists(store_dir)) dir.create(store_dir)
4855

56+
if (use_aws_s3) {
57+
tar_option_set(
58+
repository = "aws",
59+
resources = tar_resources(
60+
aws = tar_resources_aws(
61+
bucket = "forecasting-team-data",
62+
prefix = aws_s3_prefix
63+
)
64+
)
65+
)
66+
}
67+
4968
tar_manifest()
5069
if (debug_mode) {
5170
tar_make(callr_function = NULL)

0 commit comments

Comments
 (0)