R/get_species_names.R

Defines functions get_species_names

Documented in get_species_names

#' Get species names from column names
#'
#' @description
#' Gets species names from column names. This function is just an utility to
#' easily retrieve taxon names.
#'
#' @param data a `tibble` or a `data.frame`. One obtained by `read_*_data()`
#'   functions.
#'
#' @export
#'
#' @return A `character` vector of species names.
#'
#' @examples
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#'                          package = "forcis")
#'
#' net_data <- read.csv(file_name)
#'
#' # Select a taxonomy ----
#' net_data <- select_taxonomy(net_data, taxonomy = "VT")
#'
#' # Retrieve taxon names ----
#' get_species_names(net_data)

get_species_names <- function(data) {
  check_if_df(data)

  ## Special case for CPR North ----

  if (get_data_type(data) == "CPR North") {
    species_names <- unique(data$"species")

    ## Otherwise ----
  } else {
    species_names <- colnames(data)[which(
      colnames(data) %in%
        species_list()[, "taxon"]
    )]
  }

  species_names
}

Try the forcis package in your browser

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

forcis documentation built on June 8, 2025, 10:37 a.m.