diff --git a/NAMESPACE b/NAMESPACE index ea48180..5a5659d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(geocode) export(get_cache_dir) export(list_cached_data) export(set_cache_dir) +export(setup_address_fields) importFrom(data.table,"%chin%") importFrom(data.table,"%like%") importFrom(data.table,":=") diff --git a/R/setup_address_fields.R b/R/setup_address_fields.R new file mode 100644 index 0000000..4cde5b6 --- /dev/null +++ b/R/setup_address_fields.R @@ -0,0 +1,84 @@ +#' Specify the columns describing the address fields +#' +#' Creates a character vector specifying the columns that represent each address +#' field in the addresses table. +#' +#' @param logradouro A string. The name of the column representing the +#' *logradouro* (street address) of the address. May be `NULL` if the field is +#' not specified in the addresses table. +#' @param numero A string. The name of the column representing the street number +#' of the address. May be `NULL` if the field is not specified in the +#' addresses table. +#' @param complemento A string. The name of the column representing the +#' *complemento* (additional information such as apartment, PO box, etc) of +#' the address. May be `NULL` if the field is not specified in the addresses +#' table. +#' @param cep A string. The name of the column representing the *CEP* (ZIP code) +#' of the address. May be `NULL` if the field is not specified in the +#' addresses table. +#' @param bairro A string. The name of the column representing the neighborhood +#' of the address. May be `NULL` if the field is not specified in the +#' addresses table. +#' @param municipio A string. The name of the column representing the city of +#' the address. May be `NULL` if the field is not specified in the addresses +#' table. +#' @param estado A string. The name of the column representing the state of the +#' address. May be `NULL` if the field is not specified in the addresses +#' table. +#' +#' @return A character vector in which the names are the address fields and the +#' values are the columns that represent them in the addresses table. +#' +#' @examples +#' setup_address_fields( +#' logradouro = "Nome_logradouro", +#' numero = "Numero", +#' complemento = "Comp", +#' cep = "CEP", +#' bairro = "Bairro", +#' municipio = "Cidade", +#' estado = "UF" +#' ) +#' +#' @export +setup_address_fields <- function(logradouro = NULL, + numero = NULL, + complemento = NULL, + cep = NULL, + bairro = NULL, + municipio = NULL, + estado = NULL) { + col <- checkmate::makeAssertCollection() + checkmate::assert_string(logradouro, null.ok = TRUE, add = col) + checkmate::assert_string(numero, null.ok = TRUE, add = col) + checkmate::assert_string(complemento, null.ok = TRUE, add = col) + checkmate::assert_string(cep, null.ok = TRUE, add = col) + checkmate::assert_string(bairro, null.ok = TRUE, add = col) + checkmate::assert_string(municipio, null.ok = TRUE, add = col) + checkmate::assert_string(estado, null.ok = TRUE, add = col) + checkmate::reportAssertions(col) + + address_fields <- c( + logradouro = logradouro, + numero = numero, + complemento = complemento, + cep = cep, + bairro = bairro, + municipio = municipio, + estado = estado + ) + + if (is.null(address_fields)) error_null_address_fields() + + return(address_fields) +} + +error_null_address_fields <- function() { + geocodebr_error( + paste0( + "At least one of {.fn address_fields_const} ", + "arguments must not be {.code NULL}." + ), + call = rlang::caller_env() + ) +} diff --git a/man/setup_address_fields.Rd b/man/setup_address_fields.Rd new file mode 100644 index 0000000..6a9efd0 --- /dev/null +++ b/man/setup_address_fields.Rd @@ -0,0 +1,66 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/address_fields_const.R +\name{setup_address_fields} +\alias{setup_address_fields} +\title{Specify the columns describing the address fields} +\usage{ +setup_address_fields( + logradouro = NULL, + numero = NULL, + complemento = NULL, + cep = NULL, + bairro = NULL, + municipio = NULL, + estado = NULL +) +} +\arguments{ +\item{logradouro}{A string. The name of the column representing the +\emph{logradouro} (street address) of the address. May be \code{NULL} if the field is +not specified in the addresses table.} + +\item{numero}{A string. The name of the column representing the street number +of the address. May be \code{NULL} if the field is not specified in the +addresses table.} + +\item{complemento}{A string. The name of the column representing the +\emph{complemento} (additional information such as apartment, PO box, etc) of +the address. May be \code{NULL} if the field is not specified in the addresses +table.} + +\item{cep}{A string. The name of the column representing the \emph{CEP} (ZIP code) +of the address. May be \code{NULL} if the field is not specified in the +addresses table.} + +\item{bairro}{A string. The name of the column representing the neighborhood +of the address. May be \code{NULL} if the field is not specified in the +addresses table.} + +\item{municipio}{A string. The name of the column representing the city of +the address. May be \code{NULL} if the field is not specified in the addresses +table.} + +\item{estado}{A string. The name of the column representing the state of the +address. May be \code{NULL} if the field is not specified in the addresses +table.} +} +\value{ +A character vector in which the names are the address fields and the +values are the columns that represent them in the addresses table. +} +\description{ +Creates a character vector specifying the columns that represent each address +field in the addresses table. +} +\examples{ +setup_address_fields( + logradouro = "Nome_logradouro", + numero = "Numero", + complemento = "Comp", + cep = "CEP", + bairro = "Bairro", + municipio = "Cidade", + estado = "UF" +) + +}