R/triad.R

Defines functions ts_add_triads ts_add_triad

Documented in ts_add_triad ts_add_triads

#' Add Triad
#'
#' @param child A string of the child station.
#' @param parent1 A string of the first parent station.
#' @param parent2 A string of the second parent station.
#' @inheritParams tsdbr::ts_disconnect_db
#' @return A data frame of the imported triad.
#' @export
ts_add_triad <- function(child, parent1, parent2, conn = getOption("tsdbr.conn", NULL)) {
  chk_string(child)
  chk_string(parent1)
  chk_string(parent2)
  
  triads <- data.frame(Child = child,
                       Parent1 = parent1,
                       Parent2 = parent2,
                       stringsAsFactors = FALSE)
  ts_add_triads(triads, conn)
}

#' Add Triads
#' 
#' @param triads A data frame of triads with columns Child, Parent1, Parent2.
#' @inheritParams tsdbr::ts_disconnect_db
#' @return The imported triad data.
#' @export
ts_add_triads <- function(triads, conn = getOption("tsdbr.conn", NULL)) {
  check_data(triads,
             values = list(Child  = "",
                           Parent1 = "",
                           Parent2 = ""
             ),
             nrow = TRUE)
  
  
  triads <- triads[c("Child", "Parent1", "Parent2")]
  
  add(triads, "Triad", conn)
}
poissonconsulting/tscbh documentation built on Oct. 23, 2023, 11:30 p.m.