-
Notifications
You must be signed in to change notification settings - Fork 25
Migrate metadata from safetyGraphics to safetyCharts #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a7468f0
initial commit for makeMeta function
jwildfire 94da5ff
typo clean up
jwildfire 334affb
start refactor for chart level metadata
jwildfire 1e29d32
more makeMeta updates
jwildfire 42e7c4c
shell for unit tests
jwildfire c992a6c
test for charts with existing metadata
jwildfire 70fd7d0
test for charts with existing metadata
jwildfire 643483c
add tests for domain metadata import
jwildfire 1b057ec
test for chart-level metadata
jwildfire d6fc9ac
refactor makeMeta to work across all charts. #637
jwildfire 8dd7adf
add support for chart and more tests for makeMeta. #637
jwildfire 9e5b050
fix test and check issues caused by meta migration
jwildfire e1c4038
update test apps
jwildfire 29cae98
return placeholder object for evaluation of data when no defaults ar…
jwildfire eac1cf0
merge dev
jwildfire 7c1e52c
Update R/makeMeta.R
jwildfire aeff1b7
Update DESCRIPTION
jwildfire 691a3bb
Update tests/testthat/module_examples/chartsTab/app.R
jwildfire b477a00
update docs
jwildfire d98b864
update docs
jwildfire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,5 @@ | |
| ^rsconnect$ | ||
| ^LICENSE\.md$ | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #' Create a metadata object table for a set of charts | ||
| #' | ||
| #' Generates metadata object for a list of charts. `makeMeta()` looks for metadata in 3 locations for each `chart` object: | ||
| #' - Domain-level metadata saved as meta_{chart$name} in the chart$package namespace | ||
| #' - Chart-specific metadata saved as meta_{chart$domain} in the chart$package namespace | ||
| #' - Chart-specific metadata saved directly to the chart object as chart$meta | ||
| #' After checking all charts, all metadata files are stacked in to a single dataframe and returned. If duplicate metadata rows (domain + text_key) are found, an error is thrown. | ||
| #' | ||
| #' @param charts list of safetyGraphics chart objects for which to create metadata | ||
| #' | ||
| #' @return tibble of metadata with the following columns: | ||
| #' \describe{ | ||
| #' \item{domain}{Data domain} | ||
| #' \item{text_key}{Text key indicating the setting name. \code{'--'} delimiter indicates a field level data mapping} | ||
| #' \item{col_key}{Key for the column mapping} | ||
| #' \item{field_key}{Key for the field mapping (if any)} | ||
| #' \item{type}{type of mapping - "field" or "column"} | ||
| #' \item{label}{Label} | ||
| #' \item{description}{Description} | ||
| #' \item{multiple}{Mapping supports multiple columns/fields } | ||
| #' \item{standard_adam}{Default values for the ADaM data standard} | ||
| #' \item{standard_sdtm}{Default values for the SDTM data standard} | ||
| #' } | ||
| #' | ||
| #' @importFrom tidyr replace_na starts_with | ||
| #' @export | ||
|
|
||
| makeMeta <- function(charts){ | ||
| message(paste0("-Generating meta data for ",length(charts), " charts.")) | ||
| # Check each chart to see if {package}::meta_{domain} or {package}::meta_{name} exists | ||
| sources <- charts %>% map(function(chart){ | ||
| pkg<-ifelse(is.null(chart$package), 'safetyCharts',chart$package) | ||
| files<-paste0('meta_',c(chart$name, chart$domain)) %>% map(~list(file=.x, pkg=pkg)) | ||
| return(files) | ||
| }) %>% | ||
| flatten %>% | ||
| unique | ||
|
|
||
| pkg_dfs<-sources %>% map(function(src){ | ||
| packagePath <- paste0('package:',src$pkg) | ||
| file_found <- exists( | ||
| src$file, | ||
| where=packagePath, | ||
| inherits=FALSE | ||
| ) | ||
| if(file_found){ | ||
| this_meta <- get( | ||
| src$file, | ||
| pos=packagePath, | ||
| inherits=FALSE | ||
| ) | ||
|
|
||
| if(is.data.frame(this_meta)){ | ||
| this_meta <- this_meta%>% | ||
| mutate(source = paste0(src$pkg, "::",src$file)) | ||
| return(this_meta) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| ## check for meta bound directly to the charts | ||
| chart_dfs <- charts %>% map(function(chart){ | ||
| if(is.data.frame(chart$meta)){ | ||
| this_meta <- chart$meta %>% mutate(source = paste0('charts$', chart$name, "$meta")) | ||
| return(this_meta) | ||
| }else{ | ||
| if(!is.null(chart$meta)) warning(paste0("Ignoring non-data.frame object found in charts$", chart$name, "$meta")) | ||
| } | ||
| }) | ||
|
|
||
| ## make sure dfs have required columns | ||
| dfs<-c(pkg_dfs,chart_dfs) | ||
| required_cols <- c("domain","text_key","col_key","type") | ||
| dfs <- dfs%>% | ||
| keep(is.data.frame)%>% | ||
| keep(function(df){ | ||
| has_cols <- all(required_cols %in% names(df)) | ||
| if(!has_cols) warning(paste(df[1,'source'],"dropped from meta because of missing required columns.")) | ||
| return(has_cols) | ||
| }) | ||
|
|
||
| ## combine list of dfs into single df | ||
| if(length(dfs)>0){ | ||
| meta<-bind_rows(dfs) | ||
| #%>% mutate_at(vars(tidyr::starts_with('standard_')), ~tidyr::replace_na(., "")) | ||
jwildfire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Throw error if duplicate records are found | ||
| dupes <- duplicated(meta%>%select(.data$domain, .data$text_key)) | ||
| if(any(dupes)){ | ||
| dupeIDs <- meta[dupes,]%>% | ||
| mutate(domain_text_key=paste(.data$domain,.data$text_key,sep="-"))%>% | ||
| pull(.data$domain_text_key)%>% | ||
| unique%>% | ||
| paste(collapse="\n") | ||
| stop(paste("Duplicate rows in metadata for:\n",dupeIDs)) | ||
| } | ||
|
|
||
| sources <- meta %>% pull(source) %>% unique %>% paste(collapse=" ") | ||
| message(paste0("-Meta object created using the following source(s): ",sources)) | ||
| return(meta) | ||
| } else { | ||
| stop("No metadata found. ") | ||
| } | ||
|
|
||
| } | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.