Skip to content

Commit

Permalink
Changes in functions comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Haydée Svab committed Oct 7, 2023
1 parent 23d5203 commit 06ca768
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
22 changes: 13 additions & 9 deletions R/read_dictionary.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Download data dictionary from OD surveys databases
#'
#' @description
#' # The "read_dictionary" function requires as parameter city, year and whether
#' The "read_dictionary" function requires as parameter city, year and whether
#' you want the harmonized database (over the years, for the same city) or not -
#' the default is the raw base.
#'
Expand All @@ -13,42 +13,46 @@
#'
#' @return A `"data.frame"` object.
#' @export
#' @family Microdata
#' @family Documentation
#'
#' @examples
#' library(odbr)
#'
#' # return data origin destination database as data.frame
#' # return data dictionary from OD Surveys, as data.frame, at a given city and year
#' df <- read_od(
#' city = "São Paulo",
#' year = 1977,
#' harmonize = FALSE
#' harmonize = FALSE,
#' language = "pt"
#' )
#'
read_dictionary <- function(city = "São Paulo",
year = 1977,
harmonize = FALSE,
language = "pt") {
# Argument check - if it is passed a non-existent city in odbr, it gives an error message
# Argument check - error message if it is passed a non-existent city parameter
if (!city %in% metadata$city) {
usethis::ui_stop("The specified city ({city}) is not available.")
# Check the metadata object for available cities and cohorts.")
}

# Argument check - if it is passed a valid city but with a non-existent year in
# odbr, it gives an error message
# Argument check - error message if it is passed a non-existent year parameter
if (!year %in% metadata$year) {
usethis::ui_stop("The specified year ({year}) is not available.
Check the metadata object for available years and cohorts.")
}

# Argument check - if it is passed a valid city with a valid year, but with a
# non-existent harmonized parameter, it gives an error message
# Argument check - error message if it is passed a non-existent harmonized parameter
if (!harmonize %in% metadata$harmonized) {
usethis::ui_stop("The specified harmonized parameter ({harmonize}) is not available.
Check the metadata object for available harmonizeed parameters and cohorts.")
}

# Argument check - error message if it is passed a non-existent language parameter
if (!language %in% metadata$language) {
usethis::ui_stop("The specified language parameter ({language}) is not available.
Check the metadata object for available language parameters and cohorts.")
}
# Creating the filename to download
lanaguage_text <- gsub(" ", "_", tolower(iconv(city, to = "ASCII//TRANSLIT")))
filename_to_download <- paste0(compose_name(city, year, harmonize), "_dictionary_", language_text, ".csv")
Expand Down
11 changes: 5 additions & 6 deletions R/read_od.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @examples
#' library(odbr)
#'
#' # return data origin destination database as data.frame
#' # return data from OD Surveys database as data.frame
#' df <- read_od(
#' city = "São Paulo",
#' year = 1977,
Expand All @@ -26,21 +26,20 @@
read_od <- function(city = "São Paulo",
year = 1977,
harmonize = FALSE) {
# Argument check - if it is passed a non-existent city in odbr, it gives an error message

# Argument check - error message if it is passed a non-existent city parameter
if (!city %in% metadata$city) {
usethis::ui_stop("The specified city ({city}) is not available.
Check the metadata object for available cities and cohorts.")
}

# Argument check - if it is passed a valid city but with a non-existent year in
# odbr, it gives an error message
# Argument check - error message if it is passed a non-existent year parameter
if (!year %in% metadata$year) {
usethis::ui_stop("The specified year ({year}) is not available.
Check the metadata object for available years and cohorts.")
}

# Argument check - if it is passed a valid city with a valid year, but with a
# non-existent harmonized parameter, it gives an error message
# Argument check - error message if it is passed a non-existent harmonized parameter
if (!harmonize %in% metadata$harmonized) {
usethis::ui_stop("The specified harmonized parameter ({harmonize}) is not available.
Check the metadata object for available harmonized parameters and cohorts.")
Expand Down

0 comments on commit 06ca768

Please sign in to comment.