Skip to content

Commit 47012b2

Browse files
committed
improved error feedback
1 parent 4353452 commit 47012b2

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

R/domain_mapping.R

+13-7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ domain_mapping <- function(json_file = NULL, domain_file = NULL, look_up_file =
9898
nTables_Process_Error <- TRUE
9999
nTables_Process_OutOfRange <- FALSE
100100
while (length(nTables_Process) == 0 | nTables_Process_Error==TRUE | nTables_Process_OutOfRange == TRUE) {
101+
if (nTables_Process_OutOfRange == TRUE) {
102+
cli_alert_danger('That table number is not within the range displayed, please try again.')}
101103
tryCatch({
102104
cat("\n \n");
103105
cli_alert_info("Enter each table number you want to process in this interactive session:");
@@ -204,16 +206,18 @@ domain_mapping <- function(json_file = NULL, domain_file = NULL, look_up_file =
204206

205207
# extract the rows to edit
206208
auto_row_Error <- TRUE
207-
auto_row_OutOfRange <- FALSE
208-
while (auto_row_Error==TRUE | auto_row_OutOfRange == TRUE) {
209+
auto_row_InRange <- TRUE
210+
while (auto_row_Error==TRUE | auto_row_InRange == FALSE) {
211+
if (auto_row_InRange == FALSE) {
212+
cli_alert_danger('The row numbers you provided are not in range. Reference the auto categorised row numbers on the screen and try again')}
209213
tryCatch({
210214
cat("\n \n");
211215
cli_alert_info("Press enter to accept the auto categorisations for table {meta_json$dataModel$childDataClasses[[dc]]$label} or enter each row you'd like to edit:");
212216
cat("\n");
213217
auto_row <- scan(file="",what=0);
214218
auto_row_Error <- FALSE;
215-
auto_row_OutOfRange = any(auto_row > nrow(selectTable_df))},
216-
error=function(e) {auto_row_Error <- TRUE; print(e); cat("\n"); cli_alert_danger('Your input is in the wrong format, reference the row numbers and try again')})
219+
auto_row_InRange <- all(auto_row %in% which(Output$Note == 'AUTO CATEGORISED'))},
220+
error=function(e) {auto_row_Error <- TRUE; print(e); cat("\n"); cli_alert_danger('Your input is in the wrong format, try again')})
217221
}
218222

219223
if (length(auto_row) != 0) {
@@ -243,15 +247,17 @@ domain_mapping <- function(json_file = NULL, domain_file = NULL, look_up_file =
243247

244248
# extract the rows to edit
245249
not_auto_row_Error <- TRUE
246-
not_auto_row_OutOfRange <- FALSE
247-
while (not_auto_row_Error==TRUE | not_auto_row_OutOfRange == TRUE) {
250+
not_auto_row_InRange <- TRUE
251+
while (not_auto_row_Error==TRUE | not_auto_row_InRange == FALSE) {
252+
if (not_auto_row_InRange == FALSE) {
253+
cli_alert_danger('The row numbers you provided are not in range. Reference the row numbers on the screen and try again')}
248254
tryCatch({
249255
cat("\n \n");
250256
cli_alert_info("Press enter to accept your categorisations for table {meta_json$dataModel$childDataClasses[[dc]]$label} or enter each row you'd like to edit:");
251257
cat("\n");
252258
not_auto_row <- scan(file="",what=0);
253259
not_auto_row_Error <- FALSE;
254-
not_auto_row_OutOfRange = any(not_auto_row > nrow(selectTable_df))},
260+
not_auto_row_InRange <- all(not_auto_row %in% which(Output$Note != 'AUTO CATEGORISED'))},
255261
error=function(e) {not_auto_row_Error <- TRUE; print(e); cat("\n"); cli_alert_danger('Your input is in the wrong format, reference the row numbers and try again')})
256262
}
257263

0 commit comments

Comments
 (0)