sizespectrum / mizer

Multi-species size-based ecological modelling in R
https://sizespectrum.org/mizer
38 stars 43 forks source link

Make accessing and changing individual species and gear parameters easier #212

Closed gustavdelius closed 3 years ago

gustavdelius commented 3 years ago

Currently if one wants to change a species parameter for a particular species, say biomass_observed for Cod, the syntax is

species_params(params)$biomass_observed[[species_params(params)$species == "Cod"]] <- 111

There are two obvious inconveniences here:

  1. There is no auto-completion of the name of the species parameter after you have started typing species_params(params)$bi
  2. Selecting the entry for a particular species by name is cumbersome

It would be nicer to have the syntax

species_params(params, "biomass_observed") [["Cod]] <- 111

For gear params similarly instead of

gear_params(params)$catchability[[gear_params(params)$gear == "Otter" &  gear_params(params)$species == "Cod"]] <- 1

we would prefer

gear_params(params, catchability)[[Otter", "Cod"]] <- 1
gustavdelius commented 3 years ago

I am not sure what I was thinking when I wrote the above. It must have been late at night. We can of course already select by species name. So the first line in the above post is just a complicated way of writing

species_params(params)["Cod", "biomass_observed"] <- 111

This works because the species names are also used as the rownames for the species_params data frame (and this is enforced by validSpeciesParams(). The problem with missing autocomplete is, I am afraid, not one that can be addressed by what I was proposing above. The autocomplete is specific to the $ notation.

So improvement could only be achieved for the gear_params. The simplest would be to set the rownames of gear_params to be of the form "species, gear". Then we could write

gear_params(params)["Cod, Otter", "catchability] <- 1

I don't think this will be used very often, but there is no reason not to set rownames on gear_params, so I will add that to validGearParams().