Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
^pkgdown$
^data-raw$
^\.pre-commit-config.yaml$
^[.]?air[.]toml$
^\.vscode$
44 changes: 43 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,55 @@ Our procedures for contributing bigger changes, code in particular, generally fo
### Code style

- New code should follow the tidyverse [style guide](https://style.tidyverse.org).
You can use the [styler](https://CRAN.R-project.org/package=styler) package to apply these styles, but please don't restyle code that has nothing to do with your PR.
We use [Air](https://posit-dev.github.io/air/) for code formatting.

- We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation.

- We use [testthat](https://cran.r-project.org/package=testthat) for unit tests.
Contributions with test cases included are easier to accept.

#### Setting up Air

The project contains configuration files (`air.toml`, `.vscode/`) that ensure formatting is scoped to this repository only—your personal projects remain unaffected.

**Positron**

Air ships built-in with Positron. The project settings are already configured, so format-on-save is enabled automatically when working in this repo.

**VS Code**

1. Install the [Air extension](https://marketplace.visualstudio.com/items?itemName=Posit.air-vscode)
2. The project settings are already configured, so format-on-save is enabled automatically when working in this repo

**RStudio (2024.12.0+)**

RStudio requires manual setup. Note that RStudio does not support per-project settings, so these are global options.

1. Install the Air CLI:
- macOS/Linux: `curl -LsSf https://github.com/posit-dev/air/releases/latest/download/air-installer.sh | sh`
- macOS (Homebrew): `brew install air`
- Windows: `powershell -ExecutionPolicy Bypass -c "irm https://github.com/posit-dev/air/releases/latest/download/air-installer.ps1 | iex"`

2. In RStudio, go to **Tools > Global Options > Code > Formatting** and:
- Check "Use external formatter"
- Set "Reformat command:" to `{path/to/air} format` (find the path with `which air` on macOS/Linux)
- See the [RStudio setup guide](https://posit-dev.github.io/air/editor-rstudio.html) for more details

3. Optionally, enable format-on-save globally:
- In the same settings pane, check "Format code on save"
- **Note:** This applies to all projects, not just hubverse repos

4. If you prefer not to enable format-on-save globally, format manually before committing:
- Use **Code > Reformat Code** (Cmd/Ctrl+Shift+A) or right-click and select "Reformat Code"
- CI will check formatting on PRs and fail if code is not formatted

**Command Line**

Works from any terminal:
- Format entire project: `air format .`
- Check without modifying: `air format . --check`


## Code of Conduct

Please note that the hubExamples project is released with a
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/format-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches: [main, master]
pull_request:

name: format-check.yaml

permissions: read-all

jobs:
format-check:
name: format-check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Air
uses: posit-dev/setup-air@63e80dedb6d275c94a3841e15e5ff8691e1ab237 # v1

- name: Check formatting
run: air format . --check

5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"Posit.air-vscode"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
},
"[quarto]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "quarto.quarto"
}
}
Empty file added air.toml
Empty file.
15 changes: 12 additions & 3 deletions data-raw/generate_example_forecast_data.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
## code to prepare `forecast_outputs` dataset

library(aws.s3)

Check warning on line 3 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=3,col=1,[object_usage_linter] Could not find exported symbols for package "aws.s3" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘aws.s3’). This may lead to false positives.

Check warning on line 3 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=3,col=1,[object_usage_linter] Could not find exported symbols for package "aws.s3" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘aws.s3’). This may lead to false positives.

Check warning on line 3 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=3,col=1,[object_usage_linter] Could not find exported symbols for package "aws.s3" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘aws.s3’). This may lead to false positives.
library(dplyr)
library(hubData)

Check warning on line 5 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=5,col=1,[object_usage_linter] Could not find exported symbols for package "hubData" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘hubData’). This may lead to false positives.

Check warning on line 5 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=5,col=1,[object_usage_linter] Could not find exported symbols for package "hubData" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘hubData’). This may lead to false positives.

Check warning on line 5 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=5,col=1,[object_usage_linter] Could not find exported symbols for package "hubData" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘hubData’). This may lead to false positives.
library(readr)

Check warning on line 6 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=6,col=1,[object_usage_linter] Could not find exported symbols for package "readr" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘readr’). This may lead to false positives.

Check warning on line 6 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=6,col=1,[object_usage_linter] Could not find exported symbols for package "readr" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘readr’). This may lead to false positives.

Check warning on line 6 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=6,col=1,[object_usage_linter] Could not find exported symbols for package "readr" in libraries '/home/runner/work/_temp/Library', '/opt/R/4.5.2/lib/R/site-library', '/opt/R/4.5.2/lib/R/library' (there is no package called ‘readr’). This may lead to false positives.

s3_bucket_name <- "example-complex-forecast-hub"
check_bucket <- bucket_exists(s3_bucket_name)
if (isFALSE(check_bucket)) {{ stop("Aborting: ", s3_bucket_name, " S3 bucket not found") }}
if (isFALSE(check_bucket)) {
{

Check warning on line 11 in data-raw/generate_example_forecast_data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/generate_example_forecast_data.R,line=11,col=3,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.
stop("Aborting: ", s3_bucket_name, " S3 bucket not found")
}
}

hub_path <- s3_bucket(s3_bucket_name)

Expand All @@ -19,7 +23,8 @@
dplyr::filter(
.data[["location"]] %in% l_keep,
.data[["output_type"]] != "quantile" |
(.data[["output_type"]] == "quantile" & .data[["output_type_id"]] %in% q_lvls_keep),
(.data[["output_type"]] == "quantile" &
.data[["output_type_id"]] %in% q_lvls_keep),
.data[["reference_date"]] %in% d_keep
) |>
hubData::collect_hub()
Expand All @@ -34,7 +39,11 @@
}

create_forecast_oracle_output <- function() {
target_oracle_output_data_path <- paste("target-data", "oracle-output.csv", sep = "/")
target_oracle_output_data_path <- paste(
"target-data",
"oracle-output.csv",
sep = "/"
)
readr::read_csv(
aws.s3::get_object(target_oracle_output_data_path, bucket = s3_bucket_name),
show_col_types = FALSE
Expand Down
11 changes: 7 additions & 4 deletions data-raw/generate_example_scenario_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ library(hubEnsembles)
hub_path <- "../example-complex-scenario-hub/"

scenario_outputs <- hubData::connect_hub(hub_path) |>
dplyr::filter(target == "inc case", location == "US",
origin_date == "2021-03-07", output_type == "quantile") |>
dplyr::filter(
target == "inc case",
location == "US",
origin_date == "2021-03-07",
output_type == "quantile"
) |>
dplyr::collect() |>
dplyr::select(-age_group, -target_date)
scenario_ens <- hubEnsembles::simple_ensemble(scenario_outputs)
Expand All @@ -19,8 +23,7 @@ scenario_outputs <- hubData::as_model_out_tbl(scenario_outputs)

target_ts_data_path <- file.path(hub_path, "target-data", "time-series.parquet")
scenario_target_ts <- arrow::read_parquet(target_ts_data_path) |>
dplyr::filter(target == "inc case", location == "US",
date > "2020-10-01")
dplyr::filter(target == "inc case", location == "US", date > "2020-10-01")

usethis::use_data(scenario_outputs, overwrite = TRUE)
usethis::use_data(scenario_target_ts, overwrite = TRUE)
20 changes: 17 additions & 3 deletions tests/testthat/test-generate_example_forecast_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ source(file.path(forecast_data_path, "generate_example_forecast_data.R"))

test_that("forecast_outputs dataset is generated correctly", {
cols <- c(
"output_type", "reference_date", "horizon", "target_end_date",
"location", "model_id", "target", "output_type_id", "value"
"output_type",
"reference_date",
"horizon",
"target_end_date",
"location",
"model_id",
"target",
"output_type_id",
"value"
)

load(test_path("testdata", "forecast_outputs.rda"))
Expand All @@ -32,7 +39,14 @@ test_that("forecast_outputs dataset is generated correctly", {


test_that("forecast_oracle_output dataset is generated correctly", {
cols <- c("location", "target_end_date", "target", "output_type", "output_type_id", "oracle_value")
cols <- c(
"location",
"target_end_date",
"target",
"output_type",
"output_type_id",
"oracle_value"
)

load(test_path("testdata", "forecast_oracle_output.rda"))
expected_forecast_oracle_output <- forecast_oracle_output %>%
Expand Down
Loading