Skip to contents

Remove names from a MultiPop-class object at one or more specified nesting levels.

Usage

unnameMultiPop(x, level = Inf)

Arguments

x

A MultiPop-class object.

level

A positive integer, a vector of positive integers, or Inf. If level = Inf, names are removed at every level. If level = c(a, b), names are removed only at levels a and b. Levels must be >= 1; an error is raised if any requested level is deeper than the MultiPop's maximum depth. The top level is 1.

Value

A MultiPop-class object with names removed at the requested levels.

Details

- Top-level elements of a MultiPop have level 1; nested MultiPops increase the level by 1 per nesting.
- Passing a vector of positive integers removes names only at those exact levels.
- Using Inf removes names at every level.
- Mixing Inf with integer levels (e.g. c(1, Inf)) is not allowed and will raise an error.

Examples

# Create founder haplotypes
founderPop = quickHaplo(nInd = 10, nChr = 1, segSites = 10)

# Set simulation parameters
SP = SimParam$new(founderPop)

# Create population
pop = newPop(founderPop, simParam = SP)

# Create a multi-population with nested structure and names at each level
mp = newMultiPop(
  pop1 = pop[1:3],
  mpA = newMultiPop(
    pop2 = pop[4:6],
    mpB = newMultiPop(pop3 = pop[7:8], pop4 = pop[9:10])
  )
)
print(mp)
#> An object of class "MultiPop" with 2 item(s)
#>     Level 1:
#> |-- [[1]]  "pop1" - An object of class "Pop" with 3 individual(s): 1, 2, 3
#> `-- [[2]]  "mpA" - An object of class "MultiPop" with 2 item(s)
#>       |   Level 2:
#>       |-- [[1]]  "pop2" - An object of class "Pop" with 3 individual(s): 4, 5, 6
#>       `-- [[2]]  "mpB" - An object of class "MultiPop" with 2 item(s)
#>             |   Level 3:
#>             |-- [[1]]  "pop3" - An object of class "Pop" with 2 individual(s): 7, 8
#>             `-- [[2]]  "pop4" - An object of class "Pop" with 2 individual(s): 9, 10

# Remove only top-level names
unnameMultiPop(mp, level = 1)
#> An object of class "MultiPop" with 2 item(s)
#>     Level 1:
#> |-- [[1]] An object of class "Pop" with 3 individual(s): 1, 2, 3
#> `-- [[2]] An object of class "MultiPop" with 2 item(s)
#>       |   Level 2:
#>       |-- [[1]]  "pop2" - An object of class "Pop" with 3 individual(s): 4, 5, 6
#>       `-- [[2]]  "mpB" - An object of class "MultiPop" with 2 item(s)
#>             |   Level 3:
#>             |-- [[1]]  "pop3" - An object of class "Pop" with 2 individual(s): 7, 8
#>             `-- [[2]]  "pop4" - An object of class "Pop" with 2 individual(s): 9, 10

# Remove names exactly at levels 2 and 3
unnameMultiPop(mp, level = c(2L, 3L))
#> An object of class "MultiPop" with 2 item(s)
#>     Level 1:
#> |-- [[1]]  "pop1" - An object of class "Pop" with 3 individual(s): 1, 2, 3
#> `-- [[2]]  "mpA" - An object of class "MultiPop" with 2 item(s)
#>       |   Level 2:
#>       |-- [[1]] An object of class "Pop" with 3 individual(s): 4, 5, 6
#>       `-- [[2]] An object of class "MultiPop" with 2 item(s)
#>             |   Level 3:
#>             |-- [[1]] An object of class "Pop" with 2 individual(s): 7, 8
#>             `-- [[2]] An object of class "Pop" with 2 individual(s): 9, 10

# Remove all names at every level
unnameMultiPop(mp, level = Inf)
#> An object of class "MultiPop" with 2 item(s)
#>     Level 1:
#> |-- [[1]] An object of class "Pop" with 3 individual(s): 1, 2, 3
#> `-- [[2]] An object of class "MultiPop" with 2 item(s)
#>       |   Level 2:
#>       |-- [[1]] An object of class "Pop" with 3 individual(s): 4, 5, 6
#>       `-- [[2]] An object of class "MultiPop" with 2 item(s)
#>             |   Level 3:
#>             |-- [[1]] An object of class "Pop" with 2 individual(s): 7, 8
#>             `-- [[2]] An object of class "Pop" with 2 individual(s): 9, 10