Skip to content

Commit dc9dc3c

Browse files
authored
Merge pull request #66 from Boehringer-Ingelheim/358964-extendable_review_options
358964 extendable review options
2 parents a2d37c2 + 40a9de6 commit dc9dc3c

6 files changed

Lines changed: 59 additions & 13 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: dv.listings
22
Type: Package
33
Title: Data listings module
4-
Version: 4.3.4-9000
4+
Version: 4.3.4-9001
55
Authors@R:
66
c(
77
person("Boehringer-Ingelheim Pharma GmbH & Co.KG", role = c("cph", "fnd")),

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# dv.listings 4.3.4-9001
2+
- Review functionality:
3+
- Allow expanding review choices
4+
15
# dv.listings 4.3.4-9000
26
- [NOT USER-FACING] Update CM.R snippet
37

R/review.R

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,38 @@ REV_load_annotation_info <- function(folder_contents, review, dataset_lists) {
198198
contents <- folder_contents[[file_path]]
199199
review_info <- RS_parse_review_codes(contents)
200200
if (!identical(review_info, review[["choices"]])) {
201-
error <- c(
202-
error,
203-
paste0(
204-
"Review choices should remain stable during the course of a trial.\n",
205-
"The original review choices are: ", paste(sprintf('"%s"', review_info), collapse = ", "), ".\n",
206-
"This restriction is likely to be lifted in a future revision of the review feature."
201+
# See if the new reviews can be appended cleanly to the old ones
202+
new_contents <- RS_compute_review_codes_memory(review[["choices"]])
203+
new_review_options_extend_old_ones <- (length(contents) < length(new_contents) &&
204+
identical(contents, new_contents[seq_along(contents)]))
205+
if (new_review_options_extend_old_ones) {
206+
epilogue <- new_contents[(length(contents) + 1):length(new_contents)]
207+
append_IO_action(list(kind = "write", path = file_path, contents = epilogue, offset = FS$WRITE_OFFSET_APPEND))
208+
} else {
209+
choices_diff_report <- local({
210+
old_choices <- review_info
211+
new_choices <- review[["choices"]]
212+
max_len <- max(length(old_choices), length(new_choices))
213+
length(old_choices) <- max_len
214+
length(new_choices) <- max_len
215+
df <- data.frame(`Old choices` = old_choices, `New choices` = new_choices, check.names = FALSE)
216+
return(capture.output(print(df)))
217+
})
218+
undo_table_s <- paste0("<pre style='max-height: 12rem;'>", paste(choices_diff_report, collapse = "<br>"), "</pre>")
219+
220+
error <- c(
221+
error,
222+
paste0(
223+
"Review choices cannot be removed or reordered during the course of a trial.<br>",
224+
"Each choice has an associated integer value that should remain constant. These are the old and new ",
225+
"review choices:<br>",
226+
undo_table_s,
227+
"The recommended action is to restore the previous review choices:<br>",
228+
paste0("<pre>choices = c(", sprintf('"%s"', review_info) |> paste(collapse = ","), ")</pre>"),
229+
"and append any extra desired choices at the end."
230+
)
207231
)
208-
# TODO: Combine new review[["choices"]] with old `review.codes`
209-
# while preserving original associated integer codes
210-
)
232+
}
211233
}
212234
} else {
213235
contents <- RS_compute_review_codes_memory(review[["choices"]])

inst/validation/specs.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ review <- specs_list(
3939
, review_reject_storage_subfolders = "review feature rejects selection of child storage subfolders"
4040
, review_reject_conflicting_connect_app_storage = "review feature rejects selection of storage folder initially created by a different Posit Connect app"
4141
, review_undo = "review feature allows per-role undoing of latest reviews"
42+
, review_allow_extension_of_review_options = "review feature allows the extension of review options in ongoing trials"
4243
)
4344
# nolint end line_length_linter
4445

tests/testthat/test-review.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ local({
136136
fs_client[["execute_IO_plan"]](info[["IO_plan"]])
137137
expect_identical(fs_contents[["dataset_list/ae_roleA.review"]][[zero_based_version_byte_pos+1L]], as.raw(1L))
138138
})
139+
140+
test_that("REV_load_annotation_info rejects all changes to `choices` except for pure append actions" |>
141+
vdoc[["add_spec"]](specs$review_allow_extension_of_review_options), {
142+
incorrect_review_config <- review
143+
incorrect_review_config[["choices"]] <- head(incorrect_review_config[["choices"]], 1) # discard all but first choice
144+
info <- REV_load_annotation_info(fs_contents, incorrect_review_config, dataset_lists)
145+
expect_length(info[["error"]], 1)
146+
147+
correct_review_config <- review
148+
correct_review_config[["choices"]] <- c(correct_review_config[["choices"]], "extra review choice")
149+
info <- REV_load_annotation_info(fs_contents, correct_review_config, dataset_lists)
150+
expect_length(info[["error"]], 0)
151+
expect_length(info[["IO_plan"]], 1)
152+
action <- info[["IO_plan"]][[1]]
153+
expect_true(
154+
action[["kind"]] == 'write' && action[["path"]] == 'dataset_list/review.codes' && action[["offset"]] == -1L
155+
)
156+
})
139157
})
140158

141159
local({

tests/testthat/test-review_invariants.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ local({
3434
fs_client[["execute_IO_plan"]](info[["IO_plan"]])
3535
expect_length(fs_state[["error"]], 0L)
3636

37-
test_that("Review error message when extra choice is provided", {
37+
test_that("Review error message when extra choice is provided in a non-trailing position", {
3838
review2 <- review
39-
review2[["choices"]] <- c(review2[["choices"]], "choiceC")
39+
review2[["choices"]] <- c("choiceC", review2[["choices"]])
4040
info <- REV_load_annotation_info(fs_contents, review2, dataset_lists)
4141
expect_true(length(info[["error"]]) == 1 &&
42-
startsWith(info[["error"]][[1]], "Review choices should remain stable during the course of a trial."))
42+
startsWith(info[["error"]][[1]],
43+
"Review choices cannot be removed or reordered during the course of a trial."))
4344
})
4445

4546
test_that("Review error message when `id_vars` is modified", {

0 commit comments

Comments
 (0)