Skip to content

Commit

Permalink
created process metadata file, currently full of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
realbp committed Mar 28, 2024
1 parent a9b7227 commit 36b3976
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/demo-crowding.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#' }
demo_crowding <- function(area, areatype, crowding, race, include_metadata=FALSE) {
req <- create_request("demographics")

resp <- req %>%
req_url_query(
stateFIPS = fips_scp(area),
Expand All @@ -71,7 +71,7 @@ demo_crowding <- function(area, areatype, crowding, race, include_metadata=FALSE
req_perform()

resp <- process_resp(resp, "demographics", include_metadata)

if (include_metadata == TRUE) {
resp$data <- resp$data %>%
setNames(c(
Expand All @@ -81,7 +81,6 @@ demo_crowding <- function(area, areatype, crowding, race, include_metadata=FALSE
"Rank"
)) %>%
mutate(across(c("Percent", "Households"), \(x) as.numeric(x)))
return(resp)
} else {
resp %>%
setNames(c(
Expand All @@ -92,4 +91,5 @@ demo_crowding <- function(area, areatype, crowding, race, include_metadata=FALSE
)) %>%
mutate(across(c("Percent", "Households"), \(x) as.numeric(x)))
}
resp <- process_metadata(resp)
}
20 changes: 20 additions & 0 deletions R/process_metadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
process_metadata <- function(resp) {
resp_data <- resp$data
resp_metadata <- resp$metadata

resp_df <- resp_data %>% as_tibble()

class(resp_df) <- c("my_tbl", class(resp_df))

attr(resp_df, "metadata") <- resp_metadata

print.my_tbl <- function(x) {
cat("Metadata:", "\n")
for (i in seq_along(attr(x, "metadata"))) {
cat(names(attr(x, "metadata"))[i], attr(x, "metadata")[[i]], "\n")
}
NextMethod(x)
invisible(x)
}
print.my_tbl(resp_df)
}

0 comments on commit 36b3976

Please sign in to comment.