Skip to contents

This function coalesces vectors (see dplyr::coalesce) from a selected data frame into a new single vector. The vectors to coalesce are collected into a list (argument to_coal) and the output vector takes the name of the list' element in which it is collected.

Usage

coalist(data, to_coal, return_dat = FALSE)

Arguments

data

Data frame from which select vectors to coalesce.

to_coal

List of vectors to coalesce. Coalesced vectors assume the name of the element of the list in which they are collected.

return_dat

Logical argument indicating whether to return the whole data frame plus the new coalesced vectors, or a new data frame constituted only by the coalesced vectors.

Value

A data frame containing the coalesced vector(s)

Examples

if (FALSE) { # \dontrun{
authentication_details <- readLines("location_of_json_file.json")
# obtain the latest version of all files corresponding to timor-landings-v1
legacy_data <-
  cloud_object_name(
    prefix = "timor-landings-v1",
    version = "latest",
    provider = "gcs",
    options = list(
      service_account_key = authentication_details,
      bucket = "my-bucket"
    )
  )

legacy_raw <-
  readr::read_csv(
    file = legacy_data, col_types =
      readr::cols(.default = readr::col_character())
  )

to_coal <- list(
  "date" = legacy_raw %>% dplyr::select("Data", "Date"),
  "trip_group/gear_type" = legacy_raw %>%
    dplyr::select(tidyselect::contains("gear")),
  "trip_group/habitat_boat" = legacy_raw %>%
    dplyr::select(tidyselect::contains("habitat"))
)

coalist(legacy_raw, to_coal, return_dat = FALSE)
} # }