generated from pharmaverse/admiraltemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
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
read and write updates #46
Open
nicholas-masel
wants to merge
18
commits into
dev
Choose a base branch
from
42-pull-variable-level-metadata-from-column-attributes
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ab1df19
initial pass at v1.1.0 updates
nicholas-masel bad3577
address comment from discussion
nicholas-masel 13c056f
Merge pull request #48 from atorus-research/dev
nicholas-masel 9cbe86e
fix object overwrite
nicholas-masel 4a5ccad
write updates
nicholas-masel 8f7adda
cleanup
nicholas-masel 680111f
put ndjson in a separate function
nicholas-masel 41ca676
add write_dataset_ndjson()
nicholas-masel a7f7b5a
add ndjson read
nicholas-masel a65ae77
stream as list instead of df since names are not on rows
nicholas-masel 5702e30
Column metasdata arguments
mstackhouse a9a8555
remove ndjson for now since streaming isn't clear w/yyjsonr and this …
nicholas-masel 8c3cd3a
Merge pull request #52 from atorus-research/gh_issue_43
nicholas-masel 3c7d002
column metadata update for new schema
nicholas-masel 9ffe789
fix column setter
nicholas-masel c542cf9
read/write updates to account for column metadata already being on th…
nicholas-masel 9ff7f46
datajson testing
nicholas-masel 5140f73
removed tests for data_metadata, dataset_metadata, time conversions, …
nicholas-masel 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 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,102 @@ | ||
#' Verify that the item metadata supplied is the appropriate format | ||
#' | ||
#' This function does the following checks and consolidates to a single error message: | ||
#' - Columns missing that must be present | ||
#' - Columns present that are not permissible | ||
#' - Columns with NAs that must be fully populated | ||
#' - Columns columns that should be character or integer but aren't | ||
#' - Within the dataType column, if the values are within the permissible list per | ||
#' the schema | ||
#' - Within the targetDataType column, if the values are within the permissible list per | ||
#' the schema | ||
#' @param items | ||
#' | ||
#' @return Error Check | ||
#' @noRd | ||
validate_dataset_columns <- function(items) { | ||
required_cols <- c("itemOID", "name", "label", "dataType") | ||
all_cols <- c("itemOID", "name", "label", "dataType", "targetDataType", "length", "displayFormat", "keySequence") | ||
|
||
# Check for missing or extraneous columns | ||
missing_cols <- setdiff(required_cols, names(items)) | ||
err_missing_cols <- sprintf("Column `%s` is missing and must be present", missing_cols) | ||
additional_cols <- setdiff(names(items), all_cols) | ||
err_additional_cols <- sprintf("Column `%s` is not a permissible column", additional_cols) | ||
|
||
# Check for for NAs in required columns | ||
any_nas <- vapply(items[intersect(required_cols, names(items))], function(X) any(is.na(X)), FUN.VALUE = TRUE) | ||
has_nas <- names(any_nas)[any_nas] | ||
err_nas <- sprintf("Column `%s` must not have NA values", has_nas) | ||
|
||
# Check columns that should be character | ||
char_cols <- intersect(c("itemOID", "name", "label", "dataType", "targetDataType", "displayFormat"), names(items)) | ||
are_char_cols <- vapply(items[char_cols], is.character, FUN.VALUE=TRUE) | ||
not_char_cols <- names(are_char_cols)[!are_char_cols] | ||
err_char_cols <- sprintf("Column `%s` must be of type character", not_char_cols) | ||
|
||
# Check columns that should be integers | ||
int_cols <- intersect(c("length", "keySequence"), names(items)) | ||
are_int_cols <- vapply(items[int_cols], is.integer, FUN.VALUE=TRUE) | ||
not_int_cols <- names(are_int_cols)[!are_int_cols] | ||
err_int_cols <- sprintf("Column `%s` must be of type integer", not_int_cols) | ||
|
||
# Check that dataType values are within the permissible list | ||
err_dataType_vars <- character() | ||
if ('dataType' %in% names(items)) { | ||
bad_dataType <- !(items$type %in% c("string", "integer", "float", "double", "decimal", "boolean", | ||
"datetime", "date", "time", "URI")) | ||
bad_dataType_vars <- items$name[bad_dataType] | ||
bad_dataType_vals <- items$type[bad_dataType] | ||
err_dataType_vars <- sprintf( | ||
paste("Variable %s has an invalid dataType value of %s.", | ||
"Must be one of string, integer, float, double, decimal, boolean, datetime, date, time, URI"), | ||
bad_dataType_vars, bad_dataType_vals | ||
) | ||
} | ||
|
||
# Check that targetDataType values are within the permissible list | ||
err_targetDataType_vars <- character() | ||
if ('targetDataType' %in% names(items)) { | ||
bad_targetDataType <- !(items$type %in% c("integer", "decimal")) | ||
bad_targetDataType_vars <- items$name[bad_targetDataType] | ||
bad_targetDataType_vals <- items$type[bad_targetDataType] | ||
err_targetDataType_vars <- sprintf( | ||
paste("Variable %s has an invalid targetDataType value of %s.", | ||
"Must be integer or decimal"), | ||
bad_targetDataType_vars, bad_targetDataType_vals | ||
) | ||
} | ||
|
||
all_errs <- c(err_missing_cols, err_additional_cols, err_nas, err_char_cols, | ||
err_int_cols, err_dataType_vars, err_targetDataType_vars) | ||
|
||
if (length(all_errs) > 0) { | ||
msg_prep <- paste0("\n\t", all_errs) | ||
err_msg <- paste0(c("Error: Issues found in items data:", msg_prep)) | ||
stop(err_msg, call.=FALSE) | ||
} | ||
} | ||
|
||
|
||
set_column_metadata <- function(columns) { | ||
# Check items before moving any further | ||
validate_dataset_columns(columns) | ||
|
||
# Attach in the variable metadata | ||
if (!("ITEMGROUPDATASEQ" %in% columns$itemOID)) { | ||
igds_row <- data.frame( | ||
itemOID = "ITEMGROUPDATASEQ", | ||
name = "ITEMGROUPDATASEQ", | ||
label = "Record Identifier", | ||
dataType = "integer" | ||
) | ||
|
||
# Match up columns and fill | ||
igds_row[setdiff(names(columns), names(igds_row))] <- NA | ||
columns[setdiff(names(igds_row), names(columns))] <- NA | ||
|
||
columns <- rbind(igds_row, columns) | ||
} | ||
|
||
columns_converted <- df_to_list_rows(columns) | ||
} |
This file contains 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicholas-masel no issue with this as is, but do we this to be a) exported, and if so, b) would we then want the first parameter back to
x
to be pipe-compatible.