diff --git a/R/modify.mdJSON.R b/R/modify.mdJSON.R index 3b23427..328a992 100644 --- a/R/modify.mdJSON.R +++ b/R/modify.mdJSON.R @@ -29,6 +29,7 @@ #' # Export JSON to disk #' write(x = new.json, file = "e.g.dictionary.json") +# parameter to turn off update prompts modify.mdJSON <- function(x, @@ -40,14 +41,14 @@ modify.mdJSON <- domainItem, allowNull, dataType, + definition, + units, unitsResolution, - fieldWidth, + isCaseSensitive, missingValue, minValue, - maxValue) { - - - + maxValue, + fieldWidth) { `%>%` <- magrittr::`%>%` if (length(x[["data"]]) > 1) { @@ -73,7 +74,7 @@ modify.mdJSON <- message(cat( paste0("\nREQUIRED: Provide the attribute or domain codeName.") )) - codeName <- as.character(readline(prompt =)) + codeName <- as.character(readline(prompt = )) } } @@ -84,23 +85,45 @@ modify.mdJSON <- } if (missing(allowNull)) { allowNull.input <- "" + } else if (!allowNull %in% c(TRUE, FALSE)) { + message("allowNull is invalid and will be ignored.") + allowNull.input <- "" } else { allowNull.input <- allowNull } if (missing(dataType)) { dataType.input <- "" + } else if (!dataType %in% dataType.vector) { + message("dataType is invalid and will be ignored.") + dataType.input <- "" } else { dataType.input <- dataType } + if (missing(definition)) { + definition.input <- "" + } else { + definition.input <- definition + } + if (missing(units)) { + units.input <- "" + } else { + units.input <- units + } if (missing(unitsResolution)) { unitsResolution.input <- "" + } else if (suppressWarnings(is.na(as.numeric(unitsResolution.input))) == TRUE) { + message("unitsResolution is invalid and will be ignored.") + unitsResolution.input <- "" } else { unitsResolution.input <- unitsResolution } - if (missing(fieldWidth)) { - fieldWidth.input <- "" + if (missing(isCaseSensitive)) { + isCaseSensitive.input <- "" + } else if (!isCaseSensitive %in% c(TRUE, FALSE)) { + message("isCaseSensitive is invalid and will be ignored.") + isCaseSensitive.input <- "" } else { - fieldWidth.input <- fieldWidth + isCaseSensitive.input <- isCaseSensitive } if (missing(missingValue)) { missingValue.input <- "" @@ -117,6 +140,17 @@ modify.mdJSON <- } else { maxValue.input <- maxValue } + if (missing(fieldWidth)) { + fieldWidth.input <- "" + } else if (!grepl("[^[:digit:]]", + format(fieldWidth.input, + digits = 20, + scientific = FALSE)) == FALSE) { + message("fieldWidth is invalid and will be ignored.") + fieldWidth.input <- "" + } else { + fieldWidth.input <- fieldWidth + } @@ -149,92 +183,98 @@ modify.mdJSON <- newattribute[[1]][["codeName"]] <- codeName ## attribute allowNull - allowNull.choice <- 0 - - while (allowNull.choice == 0) { - allowNull.choice <- - utils::menu(c("yes", "no"), - title = - cat( - paste0( - "\nREQUIRED: Are null values permitted for the attribute '", - codeName, - "'?\n" - ) - )) + if (allowNull.input == "") { + allowNull.choice <- 0 + + while (allowNull.choice == 0) { + allowNull.choice <- + utils::menu(c(TRUE, FALSE), + title = + cat( + paste0( + "\nREQUIRED: Are null values permitted for the attribute '", + codeName, + "'?\n" + ) + )) + } + allowNull.input <- c(TRUE, FALSE)[allowNull.choice] } newattribute[[1]][["allowNull"]] <- - c("yes", "no")[allowNull.choice] + allowNull.input ## attribute dataType - dataType.choice <- 0 + if (dataType.input == "") { + dataType.choice <- 0 - while (dataType.choice == 0) { - dataType.choice <- - utils::menu(c(dataType.vector), - title = cat( - paste0( - "\nREQUIRED: Select the datatype/format for entry values of the attribute '", - codeName, - "'.\n" - ) - )) + while (dataType.choice == 0) { + dataType.choice <- + utils::menu(c(dataType.vector), + title = cat( + paste0( + "\nREQUIRED: Select the datatype/format for entry values of the attribute '", + codeName, + "'.\n" + ) + )) + } + dataType.input <- dataType.vector[dataType.choice] } newattribute[[1]][["dataType"]] <- - dataType.vector[dataType.choice] + dataType.input ## attribute definition - definition.input <- "" + if (definition.input == "") { + while (definition.input == "") { + message(cat( + paste0( + "\nREQUIRED: Provide a definition for the attribute '", + codeName, + "'." + ) + )) + definition.input <- as.character(readline(prompt = )) + } + } + newattribute[[1]][["definition"]] <- definition.input + - while (definition.input == "") { + ## attribute units + if (units.input == "") { message(cat( paste0( - "\nREQUIRED: Provide a definition for the attribute '", + "\nOPTIONAL: Provide the unit-of-measure for the attribute '", codeName, - "'." + "' (e.g., meters, atmospheres, liters).\nPress Enter to omit this information." ) )) - definition.input <- as.character(readline(prompt = )) + units.input <- as.character(readline(prompt =)) } - newattribute[[1]][["definition"]] <- definition.input - - - ## attribute units - message(cat( - paste0( - "\nOPTIONAL: Provide the unit-of-measure for the attribute '", - codeName, - "' (e.g., meters, atmospheres, liters)." - ) - )) - units.input <- as.character(readline(prompt = )) newattribute[[1]][["units"]] <- units.input ## attribute unitsResolution - message(cat( - paste0( - "\nOPTIONAL: Provide the smallest unit increment (decimal) to which the attribute '", - codeName, - "' is measured (e.g., 1, .1, .01)." - ) - )) - unitsResolution.input <- as.character(readline(prompt = )) + if (unitsResolution.input == "") { + message(cat( + paste0( + "\nOPTIONAL: Provide the smallest unit increment (numeric) to which the attribute '", + codeName, + "' is measured (e.g., 1, .1, .01).\nPress Enter to omit this information." + ) + )) + unitsResolution.input <- as.character(readline(prompt = )) + } - while (!grepl("[A-Za-z^A-Za-z]", unitsResolution.input) == FALSE | - !grepl("[^[:alnum:]]", unitsResolution.input) == FALSE) { + while (suppressWarnings(is.na(as.numeric(unitsResolution.input))) == TRUE) { message(cat( paste0( - "\nunitsResolution must be numeric. Enter 'skip' to omit this information." + "\nInvalid entry: unit resolution must be numeric.\nPress Enter to omit this information." ) )) unitsResolution.input <- as.character(readline(prompt = )) - if (unitsResolution.input == "skip") { - unitsResolution.input <- "" - } } newattribute[[1]][["unitsResolution"]] <- @@ -242,74 +282,84 @@ modify.mdJSON <- ## attribute isCaseSensitive - isCaseSensitive.choice <- - utils::menu(c("yes", "no"), - title = - cat( - paste0( - "\nOPTIONAL: Are the entry values of the attribute '", - codeName, - "' encoded in case-sensitive ASCII?\n" - ) - )) - if (isCaseSensitive.choice == 0) { - isCaseSensitive.choice <- "" - } else{ - isCaseSensitive.choice <- c("yes", "no")[isCaseSensitive.choice] + if (isCaseSensitive.input == "") { + isCaseSensitive.choice <- + utils::menu(c(TRUE, FALSE), + title = + cat( + paste0( + "\nOPTIONAL: Are the entry values of the attribute '", + codeName, + "' encoded in case-sensitive ASCII?\nEnter '0' to omit this information.\n" + ) + )) + if (isCaseSensitive.choice == 0) { + isCaseSensitive.input <- "" + } else{ + isCaseSensitive.input <- c(TRUE, FALSE)[isCaseSensitive.choice] + } } newattribute[[1]][["isCaseSensitive"]] <- - isCaseSensitive.choice + isCaseSensitive.input ## attribute missingValue - if (c("yes", "no")[allowNull.choice] == "yes") { + if (c(TRUE, FALSE)[allowNull.choice] == TRUE) { + if (missingValue.input == "") { + message(cat( + paste0( + "\nOPTIONAL: Provide the code which represents missing entry values for the attribute '", + codeName, + "' (e.g., NA, na, -).\nPress Enter to omit this information." + ) + )) + missingValue.input <- as.character(readline(prompt = )) + newattribute[[1]][["missingValue"]] <- + missingValue.input + } + } + + + ## attribute minValue + if (minValue.input == "") { message(cat( paste0( - "\nOPTIONAL: Provide the code which represents missing entry values for the attribute '", + "\nOPTIONAL: Provide the minimum value permissible for the attribute '", codeName, - "' (e.g., NA, na, -)." + "'.\nPress Enter to omit this information." ) )) - missingValue.input <- as.character(readline(prompt = )) - newattribute[[1]][["missingValue"]] <- - missingValue.input + minValue.input <- as.character(readline(prompt = )) } - - - ## attribute minValue - message(cat( - paste0( - "\nOPTIONAL: Provide the minimum range value permissible for the attribute '", - codeName, - "'." - ) - )) - minValue.input <- as.character(readline(prompt =)) newattribute[[1]][["minValue"]] <- minValue.input ## attribute maxValue - message(cat( - paste0( - "\nOPTIONAL: Provide the maximum range value permissible for the attribute '", - codeName, - "'." - ) - )) - maxValue.input <- as.character(readline(prompt = )) + if (maxValue.input == "") { + message(cat( + paste0( + "\nOPTIONAL: Provide the maximum value permissible for the attribute '", + codeName, + "'.\nPress Enter to omit this information." + ) + )) + maxValue.input <- as.character(readline(prompt =)) + } newattribute[[1]][["maxValue"]] <- maxValue.input ## attribute fieldWidth - message(cat( - paste0( - "\nOPTIONAL: Provide the field width (integer) of entry values for the attribute '", - codeName, - "'." - ) - )) - fieldWidth.input <- as.character(readline(prompt = )) + if (fieldWidth.input == "") { + message(cat( + paste0( + "\nOPTIONAL: Provide the field width (integer) of entry values for the attribute '", + codeName, + "'.\nPress Enter to omit this information." + ) + )) + fieldWidth.input <- as.character(readline(prompt = )) + } while (!grepl("[^[:digit:]]", format( @@ -319,18 +369,16 @@ modify.mdJSON <- )) == FALSE) { message(cat( paste0( - "\nfieldWidth must be an integer. Enter 'skip' to omit this information." + "\nThe field width must be an integer.\nPress Enter to omit this information." ) )) - fieldWidth.input <- as.character(readline(prompt =)) + fieldWidth.input <- as.character(readline(prompt = )) - if (fieldWidth.input == "skip") { - fieldWidth.input <- "" - } } newattribute[[1]][["fieldWidth"]] <- fieldWidth.input + ## Add attribute to dictionary list dictionarylist[["dataDictionary"]][["entity"]][[1]][["attribute"]][[length(dictionarylist[["dataDictionary"]][["entity"]][[1]][["attribute"]]) + 1]] <- @@ -356,7 +404,7 @@ modify.mdJSON <- uuid::UUIDgenerate(use.time = FALSE, n = 1) ## domain domainId, codeName, & definition - if (c("yes", "no")[domainId.choice] == "yes") { + if (domainId.choice == 1) { newdomain <- blankdomain newdomain[[1]][["domainId"]] <- @@ -382,10 +430,10 @@ modify.mdJSON <- } ## Describe initial domainItem, append subsequent - if (c("yes", "no")[domainItems.choice] == "yes") { - moredomainItems.choice <- "yes" + if (domainItems.choice == 1) { + moredomainItems.choice <- 1 - while (moredomainItems.choice == "yes") { + while (moredomainItems.choice == 1) { if (newdomain[[1]][["domainItem"]][[1]][["name"]] != "NA") { newdomain[[1]][["domainItem"]] <- append(newdomain[[1]][["domainItem"]], blankdomain[[1]][["domainItem"]]) @@ -405,7 +453,7 @@ modify.mdJSON <- ) )) domainItem_name.input <- - as.character(readline(prompt =)) + as.character(readline(prompt = )) } newdomain[[1]][["domainItem"]][[domainItem.num]][["name"]] <- domainItem_name.input @@ -423,7 +471,7 @@ modify.mdJSON <- ) )) domainItem_value.input <- - as.character(readline(prompt = )) + as.character(readline(prompt =)) } newdomain[[1]][["domainItem"]][[domainItem.num]][["value"]] <- domainItem_value.input @@ -441,7 +489,7 @@ modify.mdJSON <- ) )) domainItem_defintion.input <- - as.character(readline(prompt =)) + as.character(readline(prompt = )) } newdomain[[1]][["domainItem"]][[domainItem.num]][["definition"]] <- domainItem_defintion.input @@ -449,12 +497,12 @@ modify.mdJSON <- ## Check for more domainItems moredomainItems.choice <- - c("yes", "no")[utils::menu(c("yes", "no"), - title = cat( - paste0( - "\nREQUIRED: Would you like to add an additional item to the domain?" - ) - ))] + utils::menu(c("yes", "no"), + title = cat( + paste0( + "\nREQUIRED: Would you like to add an additional item to the domain?" + ) + )) } @@ -524,9 +572,9 @@ modify.mdJSON <- ## Describe initial domainItem, append subsequent - moredomainItems.choice <- "yes" + moredomainItems.choice <- 1 - while (moredomainItems.choice == "yes") { + while (moredomainItems.choice == 1) { if (newdomain[[1]][["domainItem"]][[1]][["name"]] != "NA") { newdomain[[1]][["domainItem"]] <- append(newdomain[[1]][["domainItem"]], blankdomain[[1]][["domainItem"]]) @@ -544,7 +592,7 @@ modify.mdJSON <- paste0("\nREQUIRED: Provide a name for the new domain item.") )) domainItem_name.input <- - as.character(readline(prompt =)) + as.character(readline(prompt = )) } newdomain[[1]][["domainItem"]][[domainItem.num]][["name"]] <- domainItem_name.input @@ -562,7 +610,7 @@ modify.mdJSON <- ) )) domainItem_value.input <- - as.character(readline(prompt = )) + as.character(readline(prompt =)) } newdomain[[1]][["domainItem"]][[domainItem.num]][["value"]] <- domainItem_value.input @@ -580,7 +628,7 @@ modify.mdJSON <- ) )) domainItem_defintion.input <- - as.character(readline(prompt =)) + as.character(readline(prompt = )) } newdomain[[1]][["domainItem"]][[domainItem.num]][["definition"]] <- domainItem_defintion.input @@ -588,12 +636,12 @@ modify.mdJSON <- ## Check for more domainItems moredomainItems.choice <- - c("yes", "no")[utils::menu(c("yes", "no"), - title = cat( - paste0( - "\nREQUIRED: Would you like to add an additional item to the domain?" - ) - ))] + utils::menu(c("yes", "no"), + title = cat( + paste0( + "\nREQUIRED: Would you like to add an additional item to the domain?" + ) + )) } @@ -635,13 +683,13 @@ modify.mdJSON <- )) ## Update attribute domainId if it doesn't match (assuming domain domainID is valid) attribute.domainId.choice <- - c("yes", "no")[utils::menu(c("yes", "no"), - title = cat( - paste0( - "\nWould you like to update the attribute domainId to match the existing domain?" - ) - ))] - if (attribute.domainId.choice == "yes") { + utils::menu(c("yes", "no"), + title = cat( + paste0( + "\nWould you like to update the attribute domainId to match the existing domain?" + ) + )) + if (attribute.domainId.choice == 1) { dictionarylist[["dataDictionary"]][["entity"]][[1]][["attribute"]][[attribute.num]][["domainId"]] <- dictionarylist[["dataDictionary"]][["domain"]][[domain.num]][["domainId"]] } @@ -683,9 +731,9 @@ modify.mdJSON <- newdomainItems <- blankdomainItem ## Describe initial domainItem, append subsequent - moredomainItems.choice <- "yes" + moredomainItems.choice <- 1 - while (moredomainItems.choice == "yes") { + while (moredomainItems.choice == 1) { if (newdomainItems[[1]][["name"]] != "NA") { newdomainItems <- append(newdomainItems, blankdomainItem) @@ -708,7 +756,7 @@ modify.mdJSON <- ) )) domainItem_value.input <- - as.character(readline(prompt =)) + as.character(readline(prompt = )) } } newdomainItems[[domainItem.num]][["value"]] <- @@ -716,17 +764,19 @@ modify.mdJSON <- ## domainItem name - domainItem_name.input <- "" + domainItem_name.input <- "" - while (domainItem_name.input == "") { - message(cat(paste0( + while (domainItem_name.input == "") { + message(cat( + paste0( "\nREQUIRED: Provide a name for the new entry value '", domainItem_value.input, "'." - ))) - domainItem_name.input <- - as.character(readline(prompt =)) - } + ) + )) + domainItem_name.input <- + as.character(readline(prompt = )) + } newdomainItems[[domainItem.num]][["name"]] <- domainItem_name.input @@ -738,12 +788,12 @@ modify.mdJSON <- message(cat( paste0( "\nREQUIRED: Provide a definition for the domain item '", - domainItem_name.input, + domainItem_value.input, "'." ) )) domainItem_defintion.input <- - as.character(readline(prompt = )) + as.character(readline(prompt =)) } newdomainItems[[domainItem.num]][["definition"]] <- domainItem_defintion.input @@ -751,12 +801,12 @@ modify.mdJSON <- ## Check for more domainItems moredomainItems.choice <- - c("yes", "no")[utils::menu(c("yes", "no"), - title = cat( - paste0( - "\nREQUIRED: Would you like to add an additional item to the domain?" - ) - ))] + utils::menu(c("yes", "no"), + title = cat( + paste0( + "\nREQUIRED: Would you like to add an additional item to the domain?" + ) + )) } @@ -771,7 +821,6 @@ modify.mdJSON <- } #### Update attribute info #### - if (how == "update_attribute") { ## Find attribute number attribute.num <- c() @@ -802,41 +851,406 @@ modify.mdJSON <- } + originalattribute <- + dictionarylist[["dataDictionary"]][["entity"]][[1]][["attribute"]][[attribute.num]] + + newattribute <- originalattribute + + + ## Make changes based on inputs + field.vector <- + c( + "allowNull", + "dataType", + "definition", + "units", + "unitsResolution", + "isCaseSensitive", + "missingValue", + "minValue", + "maxValue", + "fieldWidth" + ) + + ## No inputs provided + if (any(field.vector %in% ls()) == FALSE) { + update.choice <- + utils::menu(c("keep as is", "make changes"), + title = cat( + paste0("\n'", codeName, "' is described as followed.\n"), + paste0(jsonlite::toJSON(originalattribute, pretty = TRUE), sep = "\n"), + paste0("\nWould you like to do?") + )) + + } else if (any(field.vector %in% ls()) == TRUE) { + ## Inputs provided - ## allowNull - if(allowNull == "") - # change to yes or no + ## attribute allowNull + if (allowNull.input != "") { + newattribute[["allowNull"]] <- allowNull.input + } - ## dataType - # update to input dataType or choose from the dataType vector + ## attribute dataType + if (dataType.input != "") { + newattribute[["dataType"]] <- dataType.input + } - ## unitsResolution - # update to input or enter a numeric value + ## attribute unitsResolution + if (unitsResolution.input != "") { + newattribute[["unitsResolution"]] <- unitsResolution.input + } - ## fieldWidth - # update to input or enter an integer + ## attribute isCaseSensitive + if (fieldWidth.input != "") { + newattribute[["isCaseSensitive"]] <- isCaseSensitive.input + } - ## missingValue - # update to input or enter a new value + ## attribute missingValue + if (missingValue.input != "") { + newattribute[["missingValue"]] <- missingValue.input + } - ## minValue - # update to input or enter a new value + ## attribute minValue + if (minValue.input != "") { + newattribute[["minValue"]] <- minValue.input + } - ## maxValue - # update to input or enter a new value + ## attribute maxValue + if (maxValue.input != "") { + newattribute[["maxValue"]] <- maxValue.input + } + ## attribute fieldWidth + if (fieldWidth.input != "") { + newattribute[["fieldWidth"]] <- fieldWidth.input + } + update.choice <- + utils::menu( + c( + "disregard all revisions", + "make additional changes", + "looks good" + ), + title = cat( + paste0("\n'", codeName, "' has been updated as followed.\n"), + paste0(jsonlite::toJSON(newattribute, pretty = TRUE), sep = "\n"), + paste0("\nDoes this look correct?") + ) + ) + } + ## Make additional changes + while (update.choice == 2) { + field.choice <- + utils::menu(c(field.vector), + title = + cat(paste0( + "\nWhich field would you like to add/modify?\n" + ))) + # Create field if it doesn't exist - } + if (field.vector[field.choice] %in% names(newattribute) == FALSE) { + newfield <- list() + newfield[[paste0(field.vector[field.choice])]] <- "" + newattribute <- append(newattribute, newfield) + } + ## attribute allowNull + if (field.vector[field.choice] == "allowNull") { + allowNull.choice <- 0 + originalvalue <- newattribute[["allowNull"]] + allowNull.choice <- + utils::menu(c(TRUE, FALSE), + title = + cat( + paste0( + "\nAre null values permitted for the attribute '", + codeName, + "'? \nThe current value is '", + originalvalue, + "'.\n" + ) + )) + + if (allowNull.choice %in% c(1, 2)) { + allowNull.input <- c(TRUE, FALSE)[allowNull.choice] + newattribute[["allowNull"]] <- + allowNull.input + } + + ## attribute dataType + } else if (field.vector[field.choice] == "dataType") { + dataType.choice <- 0 + originalvalue <- newattribute[["dataType"]] + + dataType.choice <- + utils::menu(c(dataType.vector), + title = cat( + paste0( + "\nSelect the datatype/format for entry values of the attribute '", + codeName, + "'. \nThe current datatype is '", + originalvalue, + "'.\n" + ) + )) + + if (dataType.choice != 0) { + dataType.input <- dataType.vector[dataType.choice] + + newattribute[["dataType"]] <- + dataType.input + } + + ## attribute definition + } else if (field.vector[field.choice] == "definition") { + originalvalue <- newattribute[["definition"]] + + message(cat( + paste0( + "\nProvide a new definition for the attribute '", + codeName, + "'. \nThe current definition is '", + originalvalue, + "'\nPress Enter to abort changes." + ) + )) + definition.input <- as.character(readline(prompt = )) + + + if (definition.input != "") { + newattribute[["definition"]] <- definition.input + } + + ## attribute units + } else if (field.vector[field.choice] == "units") { + originalvalue <- newattribute[["units"]] + message(cat( + paste0( + "\nProvide the unit-of-measure for the attribute '", + codeName, + "' (e.g., meters, atmospheres, liters). \nThe current unit is '", + originalvalue, + "'. \nEnter 'rm()' to remove the current value. Press Enter to abort changes." + ) + )) + units.input <- as.character(readline(prompt =)) + if (units.input == "rm()") { + newattribute[["units"]] <- "" + } else if (units.input != "") { + newattribute[["units"]] <- units.input + } + + ## attribute unitsResolution + } else if (field.vector[field.choice] == "unitsResolution") { + originalvalue <- newattribute[["unitsResolution"]] + + message(cat( + paste0( + "\nProvide the smallest unit increment (numeric) to which the attribute '", + codeName, + "' is measured (e.g., 1, .1, .01). \nThe current unit resolution is '", + originalvalue, + "'\nEnter 'rm()' to remove the current value. Press Enter to abort changes." + ) + )) + unitsResolution.input <- as.character(readline(prompt =)) + + if (unitsResolution.input == "rm()") { + newattribute[["unitsResolution"]] <- + "" + } else if (suppressWarnings(is.na(as.numeric(unitsResolution.input))) == TRUE) { + message( + "\nInvalid entry: unit resolution must be numeric.\nThe current resolution will be retained." + ) + } else { + newattribute[["unitsResolution"]] <- + unitsResolution.input + } + + + ## attribute isCaseSensitive + } else if (field.vector[field.choice] == "isCaseSensitive") { + isCaseSensitive.choice <- 0 + originalvalue <- newattribute[["isCaseSensitive"]] + + isCaseSensitive.choice <- + utils::menu(c(TRUE, FALSE), + title = + cat( + paste0( + "\nAre the entry values of the attribute '", + codeName, + "' encoded in case-sensitive ASCII?\nThe current value is '", + originalvalue, + "'.\n" + ) + )) + + if (isCaseSensitive.choice %in% c(1, 2)) { + isCaseSensitive.input <- c(TRUE, FALSE)[isCaseSensitive.choice] + + newattribute[["isCaseSensitive"]] <- + isCaseSensitive.input + } + + ## attribute missingValue + } else if (field.vector[field.choice] == "missingValue") { + originalvalue <- newattribute[["missingValue"]] + + if ("allowNull" %in% names(newattribute) == TRUE & + newattribute[["allowNull"]] == FALSE) { + allowNull.check <- + utils::menu(c("yes", "no"), + title = + cat( + paste0( + "\nThe dictionary indicates the attribute '", + codeName, + "' does not allow null values.\nWould you still like to proceed?\n" + ) + )) + + + } else { + allowNull.check <- 1 + } + + if (allowNull.check == 1) { + message(cat( + paste0( + "\nProvide the code which represents missing entry values for the attribute '", + codeName, + "' (e.g., NA, na, -).\nThe current code is '", + originalvalue, + "'.\nEnter 'rm()' to remove the current value. Press Enter to abort changes." + ) + )) + missingValue.input <- as.character(readline(prompt =)) + + if (missingValue.input == "rm()") { + newattribute[["missingValue"]] <- "" + } else if (missingValue.input != "") { + newattribute[["missingValue"]] <- + missingValue.input + } + + } else { + message(cat(paste0("\nChanges aborted."))) + } + + ## attribute minValue + } else if (field.vector[field.choice] == "minValue") { + originalvalue <- newattribute[["minValue"]] + + message(cat( + paste0( + "\nProvide the minimum value permissible for the attribute '", + codeName, + "'.\nThe current minimum value is '", + originalvalue, + "'.\nEnter 'rm()' to remove the current value. Press Enter to abort changes." + ) + )) + minValue.input <- as.character(readline(prompt =)) + + if (minValue.input == "rm()") { + newattribute[["minValue"]] <- "" + } else if (minValue.input != "") { + newattribute[["minValue"]] <- minValue.input + } + + ## attribute maxValue + } else if (field.vector[field.choice] == "maxValue") { + originalvalue <- newattribute[["maxValue"]] + + message(cat( + paste0( + "\nProvide the maximum value permissible for the attribute '", + codeName, + "'.\nThe current maximum value is '", + originalvalue, + "'.\nEnter 'rm()' to remove the current value. Press Enter to abort changes." + ) + )) + maxValue.input <- as.character(readline(prompt =)) + + + if (maxValue.input == "rm()") { + newattribute[["maxValue"]] <- "" + } else if (minValue.input != "") { + newattribute[["maxValue"]] <- maxValue.input + } + + ## attribute fieldWidth + } else if (field.vector[field.choice] == "fieldWidth") { + originalvalue <- newattribute[["fieldWidth"]] + + message(cat( + paste0( + "\nProvide the field width (integer) of entry values for the attribute '", + codeName, + "'.\nThe current field width is '", + originalvalue, + "'\nEnter 'rm()' to remove the current value. Press Enter to abort changes." + ) + )) + fieldWidth.input <- as.character(readline(prompt =)) + + if (fieldWidth.input == "rm()") { + newattribute[["fieldWidth"]] <- "" + } else if (fieldWidth.input != "") { + if (!grepl("[^[:digit:]]", + format( + fieldWidth.input, + digits = 20, + scientific = FALSE + )) == FALSE) { + message( + "\nInvalid entry: field width must be an integer.\nThe current field width will be retained." + ) + } else { + newattribute[["fieldWidth"]] <- + fieldWidth.input + } + } + } + + update.choice <- + utils::menu( + c( + "disregard all revisions", + "make additional changes", + "looks good" + ), + title = cat( + paste0("\n'", codeName, "' has been updated as followed.\n"), + paste0(jsonlite::toJSON(newattribute, pretty = TRUE), sep = "\n"), + paste0("\nDoes this look correct?") + ) + ) + } + + + if (update.choice == 1) { + message("Operation canceled.") + + } else if (update.choice == 3) { + # update attribute in dictionary + dictionarylist[["dataDictionary"]][["entity"]][[1]][["attribute"]][[attribute.num]] <- + newattribute + + + } + } input.dxnry[["data"]][[1]][["attributes"]][["json"]] <- rjson::toJSON(dictionarylist)