Skip to content

Commit

Permalink
Merge pull request #14 from Infectious-Disease-Modeling-Hubs/enhancem…
Browse files Browse the repository at this point in the history
…ent/handle-null-taskids

Enhancement/handle null taskids
  • Loading branch information
annakrystalli authored Apr 2, 2024
2 parents 4fb92c3 + 6d9cd6a commit 1194ab2
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hubAdmin
Title: Utilities for administering hubverse Hubs
Version: 0.0.1
Version: 0.1.0
Authors@R:
c(person("Anna", "Krystalli", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-2378-4915")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# hubAdmin 0.1.0

* Allow task ID `create_task_id()` arguments `required` and `optional` to both be set to `NULL`, facilitating the encoding of `NA` task IDs in modeling tasks where no value is expected for a given task ID.

# hubAdmin 0.0.1

* Initial package release resulting from split of `hubUtils` package. See [`hubUtils` NEWS.md](https://github.com/Infectious-Disease-Modeling-Hubs/hubUtils/blob/main/NEWS.md) for details including previous release notes.
2 changes: 1 addition & 1 deletion R/create_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @seealso [create_rounds()]
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#'
#' @examples
#' rounds <- create_rounds(
Expand Down
2 changes: 1 addition & 1 deletion R/create_output_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' [create_output_type_pmf()], [create_output_type_sample()]
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#' @examples
#' create_output_type(
#' create_output_type_mean(
Expand Down
4 changes: 2 additions & 2 deletions R/create_output_type_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#' @return a named list of class `output_type_item` representing a `mean` or
#' `median` output type.
#' @inheritParams create_task_id
Expand Down Expand Up @@ -156,7 +156,7 @@ create_output_type_point <- function(output_type = c("mean", "median"),
#' @inheritParams create_output_type_mean
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#'
#' @return a named list of class `output_type_item` representing a `quantile`,
#' `cdf`, `pmf` or `sample` output type.
Expand Down
4 changes: 2 additions & 2 deletions R/create_round.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
#' of file format in `admin.json`. For more details on whether this argument can
#' be used as well as available formats, please consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#' @return a named list of class `round`.
#' @export
#' @seealso [create_rounds()]
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#' @examples
#' model_tasks <- create_model_tasks(
#' create_model_task(
Expand Down
2 changes: 1 addition & 1 deletion R/create_rounds.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @seealso [create_round()]
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#'
#' @examples
#' model_tasks <- create_model_tasks(
Expand Down
2 changes: 1 addition & 1 deletion R/create_target_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @seealso [create_target_metadata_item()]
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#'
#' @examples
#' create_target_metadata(
Expand Down
2 changes: 1 addition & 1 deletion R/create_target_metadata_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' @seealso [create_target_metadata()]
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#' @return a named list of class `target_metadata_item`.
#' @export
#'
Expand Down
7 changes: 3 additions & 4 deletions R/create_task_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @details `required` and `optional` vectors for standard task_ids defined in a Hub schema
#' must match data types and formats specified in the schema. For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file)
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html)
#'
#' JSON schema data type names differ to those in R. Use the following mappings to
#' create vectors of appropriate data types which will correspond to correct JSON
Expand All @@ -32,7 +32,7 @@
#' row.names = NULL))
#' ```
#' Values across `required` and `optional` arguments must be unique. `required`
#' and `optional` must be of the same type (unless `NULL`) and both cannot be `NULL`.
#' and `optional` must be of the same type (unless `NULL`).
#' Task_ids that represent dates must be supplied as character strings in ISO 8601
#' date format (YYYY-MM-DD). If working with date objects, please convert to character
#' (e.g. using `as.character()`) before supplying as arguments.
Expand Down Expand Up @@ -87,7 +87,6 @@ create_task_id <- function(name, required, optional,
)
}

check_prop_not_all_null(required, optional)
check_prop_type_const(required, optional)
check_prop_dups(required, optional)

Expand Down Expand Up @@ -187,7 +186,7 @@ check_prop_type_const <- function(required, optional) {
) %>%
unique()

if (length(prop_types) != 1L && !"NULL" %in% prop_types) {
if (length(prop_types) > 1L && !"NULL" %in% prop_types) {
cli::cli_abort(c(
"x" = "Arguments {.arg required} and {.arg optional}
must be of same type.",
Expand Down
2 changes: 1 addition & 1 deletion R/create_task_ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @seealso [create_task_id()]
#' @details For more details consult
#' the [documentation on `tasks.json` Hub config files](
#' https://hubdocs.readthedocs.io/en/latest/format/hub-metadata.html#hub-model-task-metadata-tasks-json-file).
#' https://hubdocs.readthedocs.io/en/latest/quickstart-hub-admin/tasks-config.html).
#'
#' @examples
#' create_task_ids(
Expand Down
2 changes: 1 addition & 1 deletion man/create_config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_output_type.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_output_type_mean.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_output_type_quantile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/create_round.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_rounds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_target_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_target_metadata_item.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/create_task_id.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/create_task_ids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions tests/testthat/_snaps/create_task_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,25 @@
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/Infectious-Disease-Modeling-Hubs/schemas/main/v2.0.1/tasks-schema.json"

# create_task_id errors correctly
---

Code
create_task_id("horizon", required = NULL, optional = NULL)
Condition
Error in `check_prop_not_all_null()`:
x Both arguments `required` and `optional` cannot be NULL.
Output
$horizon
$horizon$required
NULL
$horizon$optional
NULL
attr(,"class")
[1] "task_id" "list"
attr(,"schema_id")
[1] "https://raw.githubusercontent.com/Infectious-Disease-Modeling-Hubs/schemas/main/v2.0.1/tasks-schema.json"

---
# create_task_id errors correctly

Code
create_task_id("origin_date", required = NULL, optional = c("01/20/2023"))
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/test-create_task_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ test_that("create_task_id works correctly", {
2L
)
))
})


test_that("create_task_id errors correctly", {
expect_snapshot(
create_task_id("horizon",
required = NULL,
optional = NULL
),
error = TRUE
)
)
})


test_that("create_task_id errors correctly", {
expect_snapshot(
create_task_id("origin_date",
required = NULL,
Expand Down

0 comments on commit 1194ab2

Please sign in to comment.