Skip to contents

Merges a list of new model spaces into an existing PMLModels object.

Usage

add_Spaces(Spaces, NewSpaces, NewSpacesNames = character())

Arguments

Spaces

A PMLModels object (a named list) representing the existing collection of model spaces. Can be an empty list or a previously created PMLModels object.

NewSpaces

A list where each element is an internal representation of a single model space (e.g., the list structure produced by create_ModelPK or create_CustomSpace). If this list is named, these names will be used unless overridden by NewSpacesNames.

NewSpacesNames

An optional character vector providing explicit names for the spaces listed in NewSpaces. If provided: If omitted, the names attached to the NewSpaces list itself will be used.

Value

An updated PMLModels object (a named list) containing all the original spaces plus all spaces from NewSpaces. The class "PMLModels" is preserved.

Details

This function provides a general mechanism for combining collections of model spaces.

Naming and Collision Handling: This behavior differs from add_CustomSpace(), which automatically renames on collision. add_Spaces requires unique, non-colliding names for the merge.

See also

add_CustomSpace() for adding a single custom space with automatic renaming.

Examples

pk_model1 <-
  create_ModelPK(CompartmentsNumber = 1,
                 Absorption = "Intravenous")
pk_models2 <- create_ModelPK(CompartmentsNumber = c(2, 3),
                             Absorption = "First-Order")

# Combine two PMLModels objects (using names from pk_models2)
combined1 <- add_Spaces(pk_model1, pk_models2)
names(combined1)
#> [1] "PK1IVC" "PK2FOC" "PK3FOC"

# Combine using explicit new names
combined2 <-
  add_Spaces(pk_model1,
             pk_models2,
             NewSpacesNames = c("Model_A", "Model_B"))
names(combined2)
#> [1] "PK1IVC"  "Model_A" "Model_B"

# Add a list containing a single custom space
custom_pml <- "test(){ fixef(p=1) }"
custom_space_list <-
  create_CustomSpace(custom_pml, "MyCustom")
combined3 <-
  add_Spaces(pk_model1, custom_space_list)
names(combined3)
#> [1] "PK1IVC"   "MyCustom"