R/collect_species_count.R

Defines functions extract_species_count collect_species_count

#' Internal function to collect counts for species
#' @importFrom dplyr bind_cols
#' @importFrom dplyr select
#' @importFrom tibble tibble
#' @noRd
#' @keywords Internal
collect_species_count <- function(.query){
  result <- query_API(.query)
  counts <- lapply(result, extract_species_count) |> unlist()
  if(nrow(.query$url) > 1){
    select(.query$url, -url) |>
      bind_cols(tibble(count = counts))
  }else{
    tibble(count = counts)
  }
}

#' Internal function to extract counts for species
#' @importFrom purrr pluck
#' @noRd
#' @keywords Internal
extract_species_count <- function(x){
  pluck(x, !!!list(1, "count"))
}

Try the galah package in your browser

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

galah documentation built on Nov. 20, 2023, 9:07 a.m.