R/stab_pool_make.R

Defines functions stab_pool_make

Documented in stab_pool_make

#' Make stabilized community (mature media) into new pool
#' @description Extract the last row (last time point) of the CR_model output 
#' @name stab_pool_make
#' @param result the result tibble file (melted) directly from `CR_model`
#' @param coalescence whether to include resource in the regional pool
#' @return new species pool that can be put in `community_generate`
#' @example 
#' 
#' @export


#
stab_pool_make <- function (
 result,
 coalescence = FALSE
){
  # 
  stopifnot(is.data.frame(result),
            names(result)[1] == "time")
  
  if (coalescence == TRUE) {
    # Community coalescence (inluding resource)
    new_pool <- 
      result %>%
      filter(time == max(time)) %>%
      dplyr::select(-time) %>%
      spread(variable, value) %>%
      unlist()
    
  } else if (coalescence == FALSE) {
    # Community sampling without resource
    new_pool <- 
      result %>%
      filter(time == max(time)) %>%
      filter(grepl("X", variable)) %>%
      dplyr::select(-time) %>%
      spread(variable, value) %>%
      unlist()
  }
  
  return(new_pool)
}
Chang-Yu-Chang/MigrationCommunity documentation built on April 22, 2019, 7:36 p.m.