R/tarpan2-geo.R

#' tarpan2_geographies
#'
#' @param project_name The name of the project, also the name of the project
#' database
#'
#' @return A data frame of friendly names
tarpan2_geographies <- function(project_name) {
  if (missing(project_name))
    stop("Must provide project_name to get geographies from Tarpan 2.0.")

  tarpan2_query(
    query = "SELECT DISTINCT fname AS friendly_name FROM project_tbl",
    con = project_name
  )
}

#' tarpan2_geography_metadata
#'
#' @inheritParams tarpan2_geographies
#' @param geography character - A geography friendly name
#' @param specified_variables character - The variables to get. Defaults to "*"
#' for all variables
tarpan2_geography_metadata <- function(project_name, geography = NULL,
                                       specified_variables = "*") {
  if (missing(project_name))
    stop("Must provide project_name to get geography metadata ",
         "from Tarpan 2.0.")

  if (!is.character(specified_variables))
    specified_variables <- "*"

  if (!is.null(geography)) {
    fname_ids <- paste0("'{", paste0(geography, collapse = ", "), "}'")
    where_clause <- glue("fname = any({fname_ids})")
  } else
    where_clause <- NULL

  tarpan2_get_variables(con = project_name, variables = specified_variables,
                        table = "project_tbl", schema = "public",
                        where_clause = where_clause)
}

# tarpan2_geography_events <- function() {
#
# }
GlobalParametrics/taRpan_readonly documentation built on May 13, 2019, 11:23 a.m.