R/relocate_animals.R

Defines functions relocate_animals

Documented in relocate_animals

#' Internal to simulate_non_independence
#'
#' Relocate animals going home to a new mbrs_list slot
#'
#' @param inlist a list like mbrs_list
#' @param elem_relocate a list with same length as mbrs_list of animals to send
#' to home groups at next time slot
#' @keywords internal
relocate_animals <- function(inlist, elem_relocate){
  elem_relocate = paste(unlist(elem_relocate), sep = " ")
  removed = lapply(inlist, setdiff, elem_relocate)
  for(i in seq_along(elem_relocate)){
    home_group <- stringr::str_extract(elem_relocate[i], "\\d{1,}(?=_)")
    removed[[home_group]] <- c(removed[[home_group]], elem_relocate[i])
  }
  removed
}
gavincotterill/modulr documentation built on Nov. 30, 2022, 11:15 p.m.