R/list_all_upstream.R

Defines functions list_all_upstream

Documented in list_all_upstream

#' Identify all the subcatchments upstream of a list of specified catchments
#'
#' @param hierarchy a dataframe containing catchment id and next downstream (nextds) id fields
#' @param catchnames a vector of catchment ids for which a a list of upstream catchment
#' ids will be returned.
#' @return a list of upstream catchment ids for each catchment in catchnames
#' @note Function depends on the next downstream field in a stream network 'hierarchy' table (dataframe).
#' Can be used to support further aggregation of environmental variables for sub-catchments downstream
#' of a list of catchments of interest (e.g. for calculating barrier numbers).
#' @examples
#'#'data(mwcats)
#'
#'#find all sites upstream of the first five sites in the catchment list
#'data(mwcats)
#'
#'list_all_upstream(hierarchy = mwcats, catchname = mwcats$site[1:5])
#'
#' @export

list_all_upstream <- function(hierarchy, catchnames) {

  names(hierarchy) <- c("site", "nextds")

    all.us.sites <- vector("list", length(catchnames))

    for (i in 1:length(catchnames)) {
        us.sites <- allupstream(hierarchy, catchnames[i])
        all.us.sites[[i]] <- us.sites
    }
    return(all.us.sites)
}
nickbond/catchstats documentation built on Nov. 22, 2019, 3:41 a.m.