R/stab_pool_make.R

Defines functions stab_pool_make

<<<<<<< HEAD
#' 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
=======
#' Turn stabilized community (mature media) as a species pool
#' @description Extract the last row (last time point) of the CR_model output 
#' @name stab_pool_build
>>>>>>> 381875eedd7472bfbaf2cfd62d780ca03ff9b601
#' @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`


#
<<<<<<< HEAD
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 <-
=======
stab_pool_build <- function (
 result,
 coalescence = FALSE
){
  # 
  stopifnot(is.data.frame(result), names(result)[1] == "time")
  
  if (coalescence == TRUE) {
    # Community coalescence (including resource)
    new_pool <- 
>>>>>>> 381875eedd7472bfbaf2cfd62d780ca03ff9b601
      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 Aug. 13, 2019, 9:41 p.m.