R/table_initialize.R

Defines functions table_initialize

Documented in table_initialize

#' @title Create an empty known location table
#' 
#' @description Creates an empty known location tibble with the following 
#' columns of core metadata:
#' 
#' \itemize{
#' \item{locationID}
#' \item{locationName}
#' \item{longitude}
#' \item{latitude}
#' \item{elevation}
#' \item{countryCode}
#' \item{stateCode}
#' \item{countyName}
#' \item{timezone}
#' \item{houseNumber}
#' \item{street}
#' \item{city}
#' \item{postalCode}
#' }
#' 
#' @return Empty known location tibble with the specified metadata columns.
#' 
#' @examples 
#' library(MazamaLocationUtils)
#' 
#' # Create an empty Tbl
#' emptyTbl <- table_initialize()
#' dplyr::glimpse(emptyTbl)
#' 
#' @rdname table_initialize
#' @export 
#' @importFrom MazamaCoreUtils stopIfNull
#' @importFrom dplyr tibble filter
#' @importFrom rlang .data
table_initialize <- function() {
  
  # ----- Validate parameters --------------------------------------------------
  

  # ----- Create empty tibble --------------------------------------------------
  
  # Build up a tibble with a single record full of NAs
  locationTbl <- dplyr::tibble(
    "locationID" = as.character(NA),
    "locationName" = as.character(NA),
    "longitude" = as.numeric(NA),
    "latitude" = as.numeric(NA),
    "elevation" = as.numeric(NA),
    "countryCode" = as.character(NA),
    "stateCode" = as.character(NA),
    "countyName" = as.character(NA),
    "timezone" = as.character(NA),
    "houseNumber" = as.character(NA),
    "street" = as.character(NA),
    "city" = as.character(NA),
    "postalCode" = as.character(NA)
  )
  
  # Now search for an ID we won't find to end up with an empty tibble with 
  # the correct column names.
  locationTbl <-
    locationTbl %>%
    dplyr::filter(.data$locationID == "Rumplestiltskin")

  # ----- Return ---------------------------------------------------------------
  
  return(locationTbl)
  
}

Try the MazamaLocationUtils package in your browser

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

MazamaLocationUtils documentation built on Nov. 2, 2023, 6:16 p.m.