hubverse-org / hubAdmin

Utilities for administering hubverse Infectious Disease Modeling Hubs
https://hubverse-org.github.io/hubAdmin/
Other
1 stars 2 forks source link

Add functionality for appending new rounds to existing config #42

Open annakrystalli opened 2 days ago

annakrystalli commented 2 days ago

Background

@bsweger described the initial problem and @zkamvar helped troubleshoot:

We're setting up a hub that asks modelers to predict a different set of COVID variants for each round. So each week, our plan is to update tasks.json with a new round object in rounds. Creating a brand new task config works well, but I'm struggling to update an existing task config with a new round because read_config() returns a list and write_config() wants an object of class <config>

I used create_rounds to successfully create a new round for the hub but where I ran into trouble was manipulating the existing config file (so we can add the new round and write it back out OR write a new config file that contains all prior rounds + new round)

task_config <- hubUtils::read_config(".", config = c("tasks"))
existing_round <- task_config$rounds[[1]]

# read_config returns a list, not a config object, so you can't parse the
# rounds into round objects
class(existing_round)
[1] "list"

# thus, create_rounds fails
create_rounds(existing_round)
Error in create_rounds(existing_round) : 
  ! All items supplied must inherit from class <round>
✖ Item 1 does not.

What worked with current functionality:

new_round <- create_round(new round stuff)
task_config <- hubUtils::read_config(".", config = c("tasks"))
existing_round <- task_config$rounds[[1]]

class(existing_round) <- c("round", "list")

attr(existing_round, 'round_id') <- attr(new_round, 'round_id')
attr(existing_round, 'schema_id') <- attr(new_round, 'schema_id')
attr(existing_round, 'model_tasks[[1]]$task_ids$nowcast_date$required[[1]]') <- list(existing_round$model_tasks[[1]]$task_ids$nowcast_date$required[[1]])

brand_new_config <- create_config(create_rounds(new_round, existing_round))
write_config(brand_new_config, overwrite=TRUE, silent=TRUE)

Reasons behind difficulty

Indeed this seems like far more effort than it should have been. In truth we had only developed as far as creating a fresh config. There are reasons it has ended up less straight forward with current functionality and that's because:

Proposed functionality

Initially, create:

In time we might decide that we always want to read in config files as <config> class objects, but that requires work in hubUtils also so let's leave that as a separate task.