R/choose_esu.R

Defines functions choose.esu

Documented in choose.esu

#' Choose ESU
#'
#' Utility function to read in a esu choice from a list
#'
#' @param esu.names The ESUs/DPSs in the input csv file.
#'
#' @return A vector of ESU/DPS names.
#' @keywords utility
#'
choose.esu <- function(esu.names) {
  done <- FALSE
  while (!done) {
    nesus <- length(esu.names)
    cat(
      paste(
        "All ESUs in the data:\n",
        paste(1:nesus, ". ", esu.names, collapse = "\n ", sep = "")
      ), "\n"
    )
    esu.choice <- readline("Choose the ESU(s) by number: \n Enter single number or\n separate numbers by commas or 0 for all. ")
    esu.choice <- as.numeric(stringr::str_split(esu.choice, ",")[[1]])
    if (all(esu.choice %in% (0:nesus))) {
      if (identical(esu.choice, 0)) esu.choice <- 1:nesus
      done <- TRUE
    }
  }
  return(esu.choice)
}
nwfsc-math-bio/NWCTrends documentation built on July 1, 2023, 11:42 p.m.