R/bind_colonist_to_tbl.R

Defines functions bind_colonist_to_tbl

Documented in bind_colonist_to_tbl

#' Takes an existing instance of an `Island_tbl` class and bind the information
#' from the instance of an `Island_colonist` class to it
#'
#' @inheritParams default_params_doc
#'
#' @return An object of `Island_tbl` class
#' @export
#'
#' @examples
#' island_colonist <- DAISIEprep::island_colonist(
#'   clade_name = "bird",
#'   status = "endemic",
#'   missing_species = 0,
#'   col_time = 1,
#'   col_max_age = FALSE,
#'   branching_times = 0.5,
#'   species = "bird_a",
#'   clade_type = 1
#' )
#' island_tbl <- island_tbl()
#' bind_colonist_to_tbl(
#'   island_colonist = island_colonist,
#'   island_tbl = island_tbl
#' )
bind_colonist_to_tbl <- function(island_colonist,
                                 island_tbl) {

  # group island_colonist data into data frame
  # I(list(c(...))) keeps vector together
  island_colonist_df <- data.frame(
    clade_name = get_clade_name(island_colonist),
    status = get_status(island_colonist),
    missing_species = get_missing_species(island_colonist),
    col_time = get_col_time(island_colonist),
    col_max_age = get_col_max_age(island_colonist),
    branching_times = I(list(get_branching_times(island_colonist))),
    min_age = get_min_age(island_colonist),
    species = I(list(get_species(island_colonist))),
    clade_type = get_clade_type(island_colonist)
  )

  # combine island colonist data frame with island tbl data frame
  new_tbl <- rbind(get_island_tbl(island_tbl), island_colonist_df)

  # put new island tbl data frame into island_tbl class
  set_island_tbl(island_tbl) <- new_tbl

  # return the class
  island_tbl
}

Try the DAISIEprep package in your browser

Any scripts or data that you put into this service are public.

DAISIEprep documentation built on April 3, 2025, 9:26 p.m.