Skip to content

Commit

Permalink
created a parsing function
Browse files Browse the repository at this point in the history
  • Loading branch information
realbp committed Apr 3, 2024
1 parent a556f34 commit 69a9ba1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ URL: https://github.com/getwilds/cancerprof
BugReports: https://github.com/getwilds/cancerprof/issues
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
Imports:
cdlTools,
cli,
Expand All @@ -19,6 +19,7 @@ Imports:
magrittr,
rlang,
stringr,
tibble,
utils
Suggests:
knitr,
Expand Down
34 changes: 34 additions & 0 deletions R/parse_metadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
parse_metadata <- function(resp, key, string_list) {
resp_data <- resp$data
resp_metadata <- resp$metadata

values <- string

}

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
)

print(demo_metadata_list)
8 changes: 4 additions & 4 deletions R/process_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#'
#' @export
print.cancerprof_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")
# }
cat("Metadata:", "\n")
for (i in seq_along(attr(x, "metadata"))) {
cat(names(attr(x, "metadata"))[i], attr(x, "metadata")[[i]], "\n")
}
NextMethod(x, ...)
}

Expand Down

0 comments on commit 69a9ba1

Please sign in to comment.