gadget-framework / gadget3

TMB-based gadget implemtation
GNU General Public License v2.0
8 stars 6 forks source link

Combining lists of actions & single actions results in a mess #157

Open lentinj opened 1 month ago

lentinj commented 1 month ago

c(g3a_x(), list(g3a_x())) results in a silent mess. Either:

vbartolino commented 3 weeks ago

in the 3 species model https://github.com/vbartolino/g3_GoB/blob/main/rin_ven_her_g3/gadget3/02-setup/setup.R that seems to work. Is that a special case or I was overoptimistic about that run?

## collate the seal actions
actions_rin <- c(
  stock_actions,
  fleet_actions,
  likelihood_actions,
  time_actions,
  NULL
)
...
## collate the vendace actions
actions_ven <- c(
  stock_actions,
  fleet_actions,
  likelihood_actions,
  time_actions,
  NULL
)
...
## collate both actions together
actions <- c(actions_rin,
             actions_ven,
             NULL)
lentinj commented 3 weeks ago

No, that's absolutely fine and you've done it right. Each actions variable in your code sample is a list, so c() is just concatenating lists.

The problem comes when you try and concatenate an action to a list. For instance here:

https://github.com/gadget-framework/gadget3/blob/eb029bedbcec072cb4466ac0c3825de7bdd1548f/vignettes/introduction-single-stock.Rmd#L253-L254

The temptation is to do:

 # Wrong!
 simple_fn <- g3_to_r(c(simple_actions, g3a_report_detail(simple_actions) ))

We could make the above work, or we could error if you get it wrong. I'm not decided on the best approach yet.