Skip to content

Commit ece6f11

Browse files
committed
completed custom print for metadata
1 parent f8b9fe8 commit ece6f11

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method(print,cancerprof_metadata)
34
S3method(print,cancerprof_tbl)
45
export("%>%")
56
export(demo_crowding)

R/get-metadata.R

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
11

2-
# result <- demo_crowding(
3-
# area = "WA",
4-
# areatype = "county",
5-
# crowding = "household with >1 person per room",
6-
# race = "All Races (includes Hispanic)"
7-
# )
8-
92
#helper function to remove key from values
103
extract_values <- function(key, resp_metadata) {
114
values <- resp_metadata[grep(key, resp_metadata)]
125
values <- gsub(paste0("^\\s*", key, ":?\\s*"), "", values)
136
return(values)
147
}
158

9+
#' Custom print function
10+
#'
11+
#' This custom print function processes the
12+
#' metadata output for a response object
13+
#'
14+
#' @param x
15+
#'
16+
#' @export
17+
print.cancerprof_metadata <- function(x, ...) {
18+
19+
cat("\033[38;5;246m# Data Report: \033[39m", "\n")
20+
cat(paste(x$data_report, '"\n', sep = "", collapse = " "), "\n")
21+
22+
cat("\033[38;5;246m# Sorted By: \033[39m", "\n")
23+
cat(x$sortedby, "\n")
24+
cat("\n")
25+
26+
cat("\033[38;5;246m# Created By: \033[39m", "\n")
27+
cat(x$createdby, "\n")
28+
cat("\n")
29+
30+
cat("\033[38;5;246m# Data Sources: \033[39m", "\n")
31+
cat(x$data_sources, "\n")
32+
cat("\n")
33+
34+
cat("\033[38;5;246m# Data Dictionary: \033[39m", "\n")
35+
cat(x$data_dictionary, "\n")
36+
cat("\n")
37+
38+
cat("\033[38;5;246m# Data Limitations: \033[39m", "\n")
39+
cat(x$data_limitations, "\n")
40+
41+
invisible(x)
42+
}
43+
1644

1745
get_metadata <- function(input_tbl) {
1846
resp_metadata <- attr(input_tbl, "metadata")
1947

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

22-
report_header <- resp_metadata[1]
23-
data_report <- c(resp_metadata[2], resp_metadata[3], resp_metadata[4])
50+
data_report <- c(resp_metadata[1], resp_metadata[2], resp_metadata[3], resp_metadata[4])
2451
sortedby <- extract_values("Sorted by", resp_metadata)
2552
createdby <- extract_values("Created by", resp_metadata)
2653
data_sources <- extract_values("Source", resp_metadata)
@@ -29,13 +56,15 @@ get_metadata <- function(input_tbl) {
2956

3057

3158
demo_metadata_list <- list(
32-
report_header = report_header,
3359
data_report = data_report,
3460
sortedby = sortedby,
3561
createdby = createdby,
3662
data_sources = data_sources,
3763
data_dictionary = data_dictionary,
3864
data_limitations = data_limitations
3965
)
40-
return(demo_metadata_list)
66+
67+
class(demo_metadata_list) <- c("cancerprof_metadata", class(demo_metadata_list))
68+
69+
print.cancerprof_metadata(demo_metadata_list)
4170
}

R/process_metadata.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ process_metadata <- function(resp) {
3737
class(resp_data) <- c("cancerprof_tbl", class(resp_data))
3838
attr(resp_data, "metadata") <- resp_metadata
3939

40-
#print(resp_data)
40+
#print(resp_metadata)
4141
return(resp_data)
4242
}

man/print.cancerprof_metadata.Rd

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)