Utilities for accessing round ID metadata
Usage
get_round_idx(config_tasks, round_id)
get_round_ids(
config_tasks,
flatten = c("all", "model_task", "task_id", "none")
)
Arguments
- config_tasks
a list version of the content's of a hub's
tasks.json
config file, accessed through the"config_tasks"
attribute of a<hub_connection>
object or functionread_config()
.- round_id
Character string. Round identifier. If the round is set to
round_id_from_variable: true
, IDs are values of the task ID defined in the round'sround_id
property ofconfig_tasks
. Otherwise should match round'sround_id
value in config. Ignored if hub contains only a single round.- flatten
Character. Whether and how much to flatten output.
"all"
: Complete flattening. Returns a character vector of unique round IDs across all rounds."model_task"
: Flatten model tasks. Returns a list with an element for each round. Each round element contains a character vector of unique round IDs across all round model tasks. Only applicable ifround_id_from_variable
isTRUE
."task_id"
: Flatten task ID. Returns a nested list with an element for each round. Each round element contains a list with an element for each model task. Each model task element contains a character vector of unique round IDs. acrossrequired
andoptional
properties. Only applicable ifround_id_from_variable
isTRUE
"none"
: No flattening. Ifround_id_from_variable
isTRUE
, returns a nested list with an element for each round. Each round element contains a nested element for each model task. Each model task element contains a nested list ofrequired
andoptional
character vectors of round IDs. Ifround_id_from_variable
isFALSE
,a list with a round ID for each round is returned.
Value
the integer index of the element in config_tasks$rounds
that a
character round identifier maps to
a list or character vector of hub round IDs
A character vector is returned only if
flatten = "all"
A list is returned otherwise (see
flatten
for more details)
Functions
get_round_idx()
: Get an integer index of the element inconfig_tasks$rounds
that a character round identifier maps to.get_round_ids()
: Get a list or character vector of hub round IDs. For each round, ifround_id_from_variable
isTRUE
, round IDs returned are the values of the task ID defined in theround_id
property. Otherwise, ifround_id_from_variable
isFALSE
, the value of theround_id
property is returned.
Examples
config_tasks <- read_config(
hub_path = system.file("testhubs/simple", package = "hubUtils")
)
# Get round IDs
get_round_ids(config_tasks)
#> [1] "2022-10-01" "2022-10-08" "2022-10-15" "2022-10-22" "2022-10-29"
get_round_ids(config_tasks, flatten = "model_task")
#> [[1]]
#> [1] "2022-10-01" "2022-10-08"
#>
#> [[2]]
#> [1] "2022-10-15" "2022-10-22" "2022-10-29"
#>
get_round_ids(config_tasks, flatten = "task_id")
#> [[1]]
#> [[1]][[1]]
#> [1] "2022-10-01" "2022-10-08"
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [1] "2022-10-15" "2022-10-22" "2022-10-29"
#>
#>
get_round_ids(config_tasks, flatten = "none")
#> [[1]]
#> [[1]][[1]]
#> [[1]][[1]]$required
#> NULL
#>
#> [[1]][[1]]$optional
#> [1] "2022-10-01" "2022-10-08"
#>
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [[2]][[1]]$required
#> NULL
#>
#> [[2]][[1]]$optional
#> [1] "2022-10-15" "2022-10-22" "2022-10-29"
#>
#>
#>
# Get round integer index using a round_id
get_round_idx(config_tasks, "2022-10-01")
#> [1] 1
get_round_idx(config_tasks, "2022-10-29")
#> [1] 2