From dd325b5ea1ce3c749c13c434416f524d3b9a8f2c Mon Sep 17 00:00:00 2001 From: Anna Krystalli Date: Fri, 17 Jan 2025 10:59:11 +0200 Subject: [PATCH 1/3] Apply suggestions from review --- R/create_target_metadata_item.R | 11 ++++++----- man/create_target_metadata_item.Rd | 13 +++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/R/create_target_metadata_item.R b/R/create_target_metadata_item.R index ea4f1a7..7109a00 100644 --- a/R/create_target_metadata_item.R +++ b/R/create_target_metadata_item.R @@ -13,12 +13,13 @@ #' @param target_units character string. Unit of observation of the target. #' @param target_keys named list or `NULL`. The `target_keys` value defines a #' single target. -#' Should be `NULL` in the case where the target is not specified as a task_id +#' Should be a named list containing a single character string element. +#' The name of the element should match a `task_id` variable name within the same +#' `model_tasks` object and the value should match a single value of that variable +#' as described in +#' [target metadata section of the official hubverse documentation](https://hubverse.io/en/latest/user-guide/tasks.html#target-metadata). # nolint: line_length_linter +#' Otherwise, `NULL` in the case where the target is not specified as a task_id #' but is specified solely through the `target_id` argument. -#' Otherwise, should be a named list containing a single character string element. -#' The name of the element should match a `task_id` -#' variable name within the same `model_tasks` object and the value should match -#' a single value of that variable as described in [target metadata section of the official hubverse documentation](https://hubverse.io/en/latest/user-guide/tasks.html#target-metadata). #' @param description character string (optional). An optional verbose description #' of the target that might include information such as definitions of a 'rate' or similar. #' @param target_type character string. Target statistical data type. Consult the diff --git a/man/create_target_metadata_item.Rd b/man/create_target_metadata_item.Rd index a2c6029..cd21ee5 100644 --- a/man/create_target_metadata_item.Rd +++ b/man/create_target_metadata_item.Rd @@ -28,12 +28,13 @@ that could be used, for example, as a visualisation axis label.} \item{target_keys}{named list or \code{NULL}. The \code{target_keys} value defines a single target. -Should be \code{NULL}, in the case where the target is not specified as a task_id -but is specified solely through the \code{target_id} argument. -Otherwise, should be a named list containing a single character string element. -The name of the element should match a \code{task_id} -variable name within the same \code{model_tasks} object and the value should match -a single value of that variable.} +Should be a named list containing a single character string element. +The name of the element should match a \code{task_id} variable name within the same +\code{model_tasks} object and the value should match a single value of that variable +as described in +\href{https://hubverse.io/en/latest/user-guide/tasks.html#target-metadata}{target metadata section of the official hubverse documentation}. # nolint: line_length_linter +Otherwise, \code{NULL} in the case where the target is not specified as a task_id +but is specified solely through the \code{target_id} argument.} \item{description}{character string (optional). An optional verbose description of the target that might include information such as definitions of a 'rate' or similar.} From 40d21a9db28407fc202376596539f842ef696a6b Mon Sep 17 00:00:00 2001 From: Anna Krystalli Date: Fri, 17 Jan 2025 11:11:42 +0200 Subject: [PATCH 2/3] Change any mention of schema version v4.0.1 to v5.0.0 --- NEWS.md | 2 +- R/create_target_metadata_item.R | 6 ++-- .../_snaps/create_target_metadata_item.md | 2 +- tests/testthat/test-create_round.R | 8 ++--- .../test-create_target_metadata_item.R | 12 ++++---- tests/testthat/test-validate_config.R | 30 +++++++++---------- ...s.json => v5.0.0-tasks-2-target_keys.json} | 2 +- ...> v5.0.0-tasks-fail-round-id-pattern.json} | 2 +- ....0.0-tasks-fail-round-id-val-pattern.json} | 2 +- ...son => v5.0.0-tasks-null-target_keys.json} | 2 +- 10 files changed, 34 insertions(+), 34 deletions(-) rename tests/testthat/testdata/{v4.0.1-tasks-2-target_keys.json => v5.0.0-tasks-2-target_keys.json} (99%) rename tests/testthat/testdata/{v4.0.1-tasks-fail-round-id-pattern.json => v5.0.0-tasks-fail-round-id-pattern.json} (99%) rename tests/testthat/testdata/{v4.0.1-tasks-fail-round-id-val-pattern.json => v5.0.0-tasks-fail-round-id-val-pattern.json} (99%) rename tests/testthat/testdata/{v4.0.1-tasks-null-target_keys.json => v5.0.0-tasks-null-target_keys.json} (98%) diff --git a/NEWS.md b/NEWS.md index 3a36427..30b605b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ * Use options to set `schema_version` and `branch` arguments in `download_tasks_schema()` and the `create_*()` family of functions for creating config files programmatically. This allows for setting the schema version and branch globally for the session (#85). * Make validation of `round_id` patterns explicit. This ties in with schema version v4.0.1 where the pattern the `round_id` property must match if `round_id_from_variable` is `false` is now specified as a regular expression in the schema. This check is also now implemented dynamically on values of the `round_id` variable if `round_id_from_variable` is `true` when validating tasks.json config files. Checks on `round_id` patterns are also now implemented in `create_round()` when creating rounds programmatically. -* As of schema version v4.0.1, only a single `target_keys` element is allowed when creating target metadata items programmatically (#89). +* As of schema version v5.0.0, only a single `target_keys` element is allowed when creating target metadata items programmatically (#89). # hubAdmin 1.4.0 diff --git a/R/create_target_metadata_item.R b/R/create_target_metadata_item.R index 7109a00..ade3d03 100644 --- a/R/create_target_metadata_item.R +++ b/R/create_target_metadata_item.R @@ -155,12 +155,12 @@ check_target_keys <- function(target_keys, schema_version, call = call ) } - is_gte_v4_0_1 <- hubUtils::version_gte( - "v4.0.1", + is_gte_v5_0_0 <- hubUtils::version_gte( + "v5.0.0", schema_version = schema_version ) target_key_n <- length(target_keys) - if (is_gte_v4_0_1 && target_key_n > 1L) { + if (is_gte_v5_0_0 && target_key_n > 1L) { cli::cli_abort( c( "!" = "{.arg target_keys} must be a named {.cls list} of diff --git a/tests/testthat/_snaps/create_target_metadata_item.md b/tests/testthat/_snaps/create_target_metadata_item.md index 574c957..859795b 100644 --- a/tests/testthat/_snaps/create_target_metadata_item.md +++ b/tests/testthat/_snaps/create_target_metadata_item.md @@ -162,7 +162,7 @@ - "https://raw.githubusercontent.com/hubverse-org/schemas/main/v3.0.1/tasks-schema.json" + "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json" -# Target_keys of length more than 1 are not allowed post v4.0.1 +# Target_keys of length more than 1 are not allowed post v5.0.0 Code create_target_metadata_item(target_id = "flu inc hosp", target_name = "Weekly incident influenza hospitalizations", diff --git a/tests/testthat/test-create_round.R b/tests/testthat/test-create_round.R index 30ce7e1..a4a6f1a 100644 --- a/tests/testthat/test-create_round.R +++ b/tests/testthat/test-create_round.R @@ -229,8 +229,8 @@ test_that("validating round_id patterns when round_id_from_var = TRUE works", { skip_if_offline() withr::with_options( list( - hubAdmin.schema_version = "v4.0.1", - hubAdmin.branch = "br-v4.0.1" + hubAdmin.schema_version = "v5.0.0", + hubAdmin.branch = "br-v5.0.0" ), { output_types <- create_output_type( @@ -372,8 +372,8 @@ test_that("validating round_id pattern when round_id_from_var = FALSE works", { skip_if_offline() withr::with_options( list( - hubAdmin.schema_version = "v4.0.1", - hubAdmin.branch = "br-v4.0.1" + hubAdmin.schema_version = "v5.0.0", + hubAdmin.branch = "br-v5.0.0" ), { output_types <- create_output_type( diff --git a/tests/testthat/test-create_target_metadata_item.R b/tests/testthat/test-create_target_metadata_item.R index eba13c4..e91768b 100644 --- a/tests/testthat/test-create_target_metadata_item.R +++ b/tests/testthat/test-create_target_metadata_item.R @@ -149,16 +149,16 @@ test_that("schema version option works for create_target_metadata_item", { expect_snapshot(waldo::compare(opt_version, version_default)) }) -test_that("Target_keys of length more than 1 are not allowed post v4.0.1", { +test_that("Target_keys of length more than 1 are not allowed post v5.0.0", { skip_if_offline() withr::with_options( list( - hubAdmin.schema_version = "v4.0.1", - # TDOD: remove branch argument when v4.0.1 is released. - hubAdmin.branch = "ak/v4.0.1/restrict-target-key-value-pair-n/117" + hubAdmin.schema_version = "v5.0.0", + # TDOD: remove branch argument when v5.0.0 is released. + hubAdmin.branch = "br-v5.0.0" ), { - # One target_key is allowed in v4.0.1 and later versions. + # One target_key is allowed in v5.0.0 and later versions. target_keys_n1 <- create_target_metadata_item( target_id = "inc hosp", target_name = "Weekly incident influenza hospitalizations", @@ -171,7 +171,7 @@ test_that("Target_keys of length more than 1 are not allowed post v4.0.1", { expect_s3_class(target_keys_n1, "target_metadata_item") expect_length(target_keys_n1$target_keys, 1L) - # More than one target_key is NOT allowed in v4.0.1 and later versions + # More than one target_key is NOT allowed in v5.0.0 and later versions # and throws error. expect_snapshot( create_target_metadata_item( diff --git a/tests/testthat/test-validate_config.R b/tests/testthat/test-validate_config.R index 529f92c..95935b5 100644 --- a/tests/testthat/test-validate_config.R +++ b/tests/testthat/test-validate_config.R @@ -253,14 +253,14 @@ test_that("v4 validation works", { }) -test_that("v4.0.1 target keys with 2 properties throws error", { +test_that("v5.0.0 target keys with 2 properties throws error", { skip_if_offline() - config_path <- testthat::test_path("testdata", "v4.0.1-tasks-2-target_keys.json") + config_path <- testthat::test_path("testdata", "v5.0.0-tasks-2-target_keys.json") out <- suppressMessages( validate_config( config_path = config_path, - # TDOD: remove branch argument when v4.0.1 is released. - branch = "ak/v4.0.1/restrict-target-key-value-pair-n/117" + # TDOD: remove branch argument when v5.0.0 is released. + branch = "br-v5.0.0" ) ) expect_false(out) @@ -272,23 +272,23 @@ test_that("v4.0.1 target keys with 2 properties throws error", { expect_equal(nrow(attr(out, "errors")), 2L) }) -test_that("v4.0.1 target keys with NULL properties passes", { +test_that("v5.0.0 target keys with NULL properties passes", { # Ensure NULL target keys are still allowed. - config_path <- testthat::test_path("testdata", "v4.0.1-tasks-null-target_keys.json") + config_path <- testthat::test_path("testdata", "v5.0.0-tasks-null-target_keys.json") out <- suppressMessages( validate_config( config_path = config_path, - # TDOD: remove branch argument when v4.0.1 is released. - branch = "ak/v4.0.1/restrict-target-key-value-pair-n/117" + # TDOD: remove branch argument when v5.0.0 is released. + branch = "br-v5.0.0" ) ) expect_true(out) }) -test_that("v4.0.1 round_id pattern validation works", { +test_that("v5.0.0 round_id pattern validation works", { skip_if_offline() - # TODO: remove branch argument when v4.0.1 is released. - schema <- download_tasks_schema("v4.0.1", branch = "br-v4.0.1") + # TODO: remove branch argument when v5.0.0 is released. + schema <- download_tasks_schema("v5.0.0", branch = "br-v5.0.0") # Test that regex pattern matching for round_id properties in jsonvalidate # identifies expected errors (when round_id_from_variable: false). @@ -297,9 +297,9 @@ test_that("v4.0.1 round_id pattern validation works", { validate_config( config_path = testthat::test_path( "testdata", - "v4.0.1-tasks-fail-round-id-pattern.json" + "v5.0.0-tasks-fail-round-id-pattern.json" ), - branch = "br-v4.0.1" + branch = "br-v5.0.0" ) ) ) @@ -325,9 +325,9 @@ test_that("v4.0.1 round_id pattern validation works", { validate_config( config_path = testthat::test_path( "testdata", - "v4.0.1-tasks-fail-round-id-val-pattern.json" + "v5.0.0-tasks-fail-round-id-val-pattern.json" ), - branch = "br-v4.0.1" + branch = "br-v5.0.0" ) ) ) diff --git a/tests/testthat/testdata/v4.0.1-tasks-2-target_keys.json b/tests/testthat/testdata/v5.0.0-tasks-2-target_keys.json similarity index 99% rename from tests/testthat/testdata/v4.0.1-tasks-2-target_keys.json rename to tests/testthat/testdata/v5.0.0-tasks-2-target_keys.json index d9a8c81..182014c 100644 --- a/tests/testthat/testdata/v4.0.1-tasks-2-target_keys.json +++ b/tests/testthat/testdata/v5.0.0-tasks-2-target_keys.json @@ -1,5 +1,5 @@ { - "schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json", + "schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v5.0.0/tasks-schema.json", "rounds": [{ "round_id_from_variable": true, "round_id": "forecast_date", diff --git a/tests/testthat/testdata/v4.0.1-tasks-fail-round-id-pattern.json b/tests/testthat/testdata/v5.0.0-tasks-fail-round-id-pattern.json similarity index 99% rename from tests/testthat/testdata/v4.0.1-tasks-fail-round-id-pattern.json rename to tests/testthat/testdata/v5.0.0-tasks-fail-round-id-pattern.json index 0813782..24517c0 100644 --- a/tests/testthat/testdata/v4.0.1-tasks-fail-round-id-pattern.json +++ b/tests/testthat/testdata/v5.0.0-tasks-fail-round-id-pattern.json @@ -1,5 +1,5 @@ { - "schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json", + "schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v5.0.0/tasks-schema.json", "rounds": [{ "round_id_from_variable": true, "round_id": "round_id_var", diff --git a/tests/testthat/testdata/v4.0.1-tasks-fail-round-id-val-pattern.json b/tests/testthat/testdata/v5.0.0-tasks-fail-round-id-val-pattern.json similarity index 99% rename from tests/testthat/testdata/v4.0.1-tasks-fail-round-id-val-pattern.json rename to tests/testthat/testdata/v5.0.0-tasks-fail-round-id-val-pattern.json index ebcfd66..09a4217 100644 --- a/tests/testthat/testdata/v4.0.1-tasks-fail-round-id-val-pattern.json +++ b/tests/testthat/testdata/v5.0.0-tasks-fail-round-id-val-pattern.json @@ -1,5 +1,5 @@ { - "schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json", + "schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v5.0.0/tasks-schema.json", "rounds": [{ "round_id_from_variable": true, "round_id": "round_id_var", diff --git a/tests/testthat/testdata/v4.0.1-tasks-null-target_keys.json b/tests/testthat/testdata/v5.0.0-tasks-null-target_keys.json similarity index 98% rename from tests/testthat/testdata/v4.0.1-tasks-null-target_keys.json rename to tests/testthat/testdata/v5.0.0-tasks-null-target_keys.json index fc038f7..5dc10d0 100644 --- a/tests/testthat/testdata/v4.0.1-tasks-null-target_keys.json +++ b/tests/testthat/testdata/v5.0.0-tasks-null-target_keys.json @@ -1,5 +1,5 @@ { - "schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json", + "schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v5.0.0/tasks-schema.json", "rounds": [{ "round_id_from_variable": true, "round_id": "forecast_date", From 97bdc3fb90edafb59addaa4399b1bc6961535d90 Mon Sep 17 00:00:00 2001 From: Anna Krystalli Date: Fri, 17 Jan 2025 11:11:55 +0200 Subject: [PATCH 3/3] add Rsudio project id --- hubAdmin.Rproj | 1 + 1 file changed, 1 insertion(+) diff --git a/hubAdmin.Rproj b/hubAdmin.Rproj index 97b9e3f..a7bcba2 100644 --- a/hubAdmin.Rproj +++ b/hubAdmin.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: a853e49a-e7e8-463b-96b8-8c69e98c0382 RestoreWorkspace: No SaveWorkspace: No