Skip to content

Commit

Permalink
edited parse metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
realbp committed Apr 8, 2024
1 parent 69a9ba1 commit f06abb2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion R/demo-crowding.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#' area = "WA",
#' areatype = "county",
#' crowding = "household with >1 person per room",
#' race = "All Races (includes Hispanic)",
#' race = "All Races (includes Hispanic)",
#' include_metadata = TRUE
#' )
#'
Expand Down
53 changes: 27 additions & 26 deletions R/parse_metadata.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
parse_metadata <- function(resp, key, string_list) {
resp_data <- resp$data
resp_metadata <- resp$metadata

values <- string

}

#helper function to remove key from values
extract_values <- function(key, resp_metadata) {
values <- resp_metadata[grep(key, resp_metadata)]
values <- gsub(paste0("^\\s*", key, ":?\\s*"), "", values)
return(values)
}

report_header <- resp_metadata[1]
m_report <- c(resp_metadata[2], resp_metadata[3], resp_metadata[4])
sortedby <- extract_values("Sorted by", resp_metadata)
createdby <- extract_values("Created by", resp_metadata)
data_sources <- extract_values("Source", resp_metadata)
data_dictionary <- extract_values("For more information about", resp_metadata)
data_limitations <- extract_values("Data for", resp_metadata)


demo_metadata_list <- list(
report_header <- resp_metadata[1],
m_report <- c(resp_metadata[2], resp_metadata[3], resp_metadata[4]),
sortedby = sortedby,
createdby = createdby,
data_sources = data_sources,
data_dictionary = data_dictionary,
data_limitations = data_limitations
)
parse_metadata <- function(resp) {
resp_metadata <- resp$metadata

resp_metadata <- gsub("\\\"", "", resp_metadata)

report_header <- resp_metadata[1]
data_report <- c(resp_metadata[2], resp_metadata[3], resp_metadata[4])
sortedby <- extract_values("Sorted by", resp_metadata)
createdby <- extract_values("Created by", resp_metadata)
data_sources <- extract_values("Source", resp_metadata)
data_dictionary <- extract_values("For more information about", resp_metadata)
data_limitations <- extract_values("Data for", resp_metadata)


demo_metadata_list <- list(
report_header = report_header,
data_report = data_report,
sortedby = sortedby,
createdby = createdby,
data_sources = data_sources,
data_dictionary = data_dictionary,
data_limitations = data_limitations
)
return(demo_metadata_list)
}

print(demo_metadata_list)
parse_metadata(resp)
2 changes: 1 addition & 1 deletion R/process-resp.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#'
#' @examples
#' process_resp(resp, "demographics")
process_resp <- function(resp, topic, include_metadata = FALSE) {
process_resp <- function(resp, topic, include_metadata) {
if (httr2::resp_content_type(resp) != "text/csv") {
cli_abort("Invalid input, please check documentation for valid arguments.")
}
Expand Down

0 comments on commit f06abb2

Please sign in to comment.