Skip to content

Commit f187a04

Browse files
authored
Merge pull request #63 from Boehringer-Ingelheim/299890-remove-groupings-on-start
299890 remove groupings on start
2 parents ae3bf20 + 6188db1 commit f187a04

File tree

6 files changed

+115
-7
lines changed

6 files changed

+115
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: dv.manager
22
Type: Package
33
Title: DaVinci Module Manager
4-
Version: 2.1.12-9000
4+
Version: 2.1.13-9000
55
Authors@R: c(person("Boehringer-Ingelheim Pharma GmbH & Co.KG", role = c("cph", "fnd")),
66
person('Luis', 'Morís Fernández', email = '[email protected]', role = c('cre', 'aut')),
77
person('Sorin', 'Voicu', email = '[email protected]', role = c('aut')))

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# dv.manager 2.1.13-9000
2+
3+
- Ungroups all datasets and transform into `data.frame`
4+
15
# dv.manager 2.1.12-9000
26

37
- Refactors UI

R/run_app.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ run_app <- function(data = NULL,
6969
config <- list()
7070
config[["module_info"]] <- check_resolved_modules(process_module_list(module_list))
7171
# The automatic mapping will influence reporting when it is implemented in the future
72-
config[["data"]] <- char_vars_to_factor_vars_dataset_lists(check_data(dataset_lists))
72+
config[["data"]] <- local({
73+
check_data(dataset_lists)
74+
d <- char_vars_to_factor_vars_dataset_lists(dataset_lists)
75+
d <- ungroup2df_datasets_dataset_lists(d)
76+
d
77+
})
7378
config[["filter_data"]] <- check_filter_data(filter_data, dataset_lists)
7479
config[["filter_key"]] <- check_filter_key(filter_key, dataset_lists)
7580
config[["startup_msg"]] <- check_startup_msg(startup_msg)

R/utils_preproc.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,35 @@ char_vars_to_factor_vars_dataset_lists <- function(dataset_lists) { # nolintr
4545
}
4646
dataset_lists
4747
}
48+
49+
decorate_ungroup2df_datasets_dataset_list <- function(f) { # nolintr
50+
function() {
51+
ungroup2df_datasets_dataset_list(f())
52+
}
53+
}
54+
55+
ungroup2df_datasets_dataset_list <- function(dataset_list) { # nolintr
56+
dataset_names <- names(dataset_list)
57+
for (dataset_name in dataset_names) {
58+
dataset_list[[dataset_name]] <- as.data.frame( # Transform to base::data.frame, discards tibble related classes...
59+
dplyr::ungroup(dataset_list[[dataset_name]])
60+
)
61+
}
62+
dataset_list
63+
}
64+
65+
ungroup2df_datasets_dataset_lists <- function(dataset_lists) { # nolintr
66+
dataset_list_names <- names(dataset_lists)
67+
for (dataset_list_name in dataset_list_names) {
68+
dataset_list <- dataset_lists[[dataset_list_name]]
69+
if (is.function(dataset_list)) {
70+
ungrouped_dataset_list <- decorate_ungroup2df_datasets_dataset_list(dataset_list)
71+
} else if (is.list(dataset_list)) {
72+
ungrouped_dataset_list <- ungroup2df_datasets_dataset_list(dataset_list)
73+
} else {
74+
stop("Unknown type")
75+
}
76+
dataset_lists[[dataset_list_name]] <- ungrouped_dataset_list
77+
}
78+
dataset_lists
79+
}

inst/validation/specs.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fs_spec <- specs_list(
3434
"selected_dataset_name_access" = "Modules will have access to the name of the selected dataset",
3535
"module_name_access" = "Modules will have access to its name and the name of the other modules",
3636
"modification_dates_access" = "Modules will have access to the earliest and latest modification dates of all the data tables.",
37-
"module_tab_switching" = "dv.manager allows programatically switching from one module tab to another",
37+
"module_tab_switching" = "dv.manager allows programatically switching from one module tab to another",
3838
"SSO_authentication_option" = "dv.manager provides the option to enable the authentication of App Users with SSO to access the app.",
3939
"empty_datasets" = "dv.manager supports datasets with 0 rows"
4040
)
@@ -95,7 +95,7 @@ or a positive numeric value which is then interpreted as a lubridate duration ob
9595
"dispatchers" = "- dispatchers: A dispatcher function that simplifies the acces to datasets from the module invocation in the module list.",
9696
"SSO_login_option" = "module manager offers the option of providing an SSO login. For this the app uses the AzureAuth package.",
9797
"AzureAuth_integration" = "module manager just passes the information to AzureAuth therefore no development testing is done at this level, as it requires an Azure AD in place and it is not available at build time in Jenkins.",
98-
"data_reloading" = "Module Manager allows reloading the data after a given amount of time. The data_reload parameter will be specified by the App Creator."
98+
"data_reloading" = "Module Manager allows reloading the data after a given amount of time. The data_reload parameter will be specified by the App Creator."
9999
)
100100

101101
tab_group <- list(
@@ -110,7 +110,9 @@ filtering <- list(
110110
)
111111

112112
preprocessing <- list(
113-
"char_to_factor_mapping" = "Module manager will automatically map character columns into factors for all the variables in all the datasets loaded in the app"
113+
"char_to_factor_mapping" = "Module manager will automatically map character columns into factors for all the variables in all the datasets loaded in the app",
114+
"ungroup_datasets" = "Module manager will automatically ungroup datasets",
115+
"tibble2df" = "Module manager will automatically transform tibble in data.frames"
114116
)
115117

116118
specs <- c(

tests/testthat/test-utils-preproc.R

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ local({
5252
test_that("char_vars_to_factor_vars respect lables" |>
5353
vdoc[["add_spec"]](c(specs$preprocessing$char_to_factor_mapping)), {
5454
r <- char_vars_to_factor_vars_dataset(dl)
55-
expect_identical(attr(e1[["char_var1"]], "label"), "char_var1_label")
55+
expect_identical(attr(r[["ds1"]][["char_var1"]], "label"), "char_var1_label")
5656
})
5757

58-
test_that("decorate_char_vars_to_factor_vars_dataset_list decorates a functions that returns a list of data.frames and transforms character variables into factor variables", { # nolintr
58+
test_that("decorate_char_vars_to_factor_vars_dataset_list decorates a functions that returns a list of data.frames and transforms character variables into factor variables" |>
59+
vdoc[["add_spec"]](c(specs$preprocessing$char_to_factor_mapping)), { # nolintr
5960
f <- function() dl
6061
dec_f <- decorate_char_vars_to_factor_vars_dataset_list(f)
6162
e <- edl
@@ -85,3 +86,67 @@ local({
8586
expect_identical(r[["config"]][["data"]][["dl2"]]()[["ds2"]], expected_dataset_lists[["dl2"]]()[["ds2"]])
8687
})
8788
})
89+
90+
local({
91+
d <- data.frame(
92+
num = 1,
93+
fac = factor(c("fa"))
94+
)
95+
96+
attr(d[["num"]], "label") <- "num_label"
97+
attr(d[["fac"]], "label") <- "fac_label"
98+
99+
100+
d1 <- dplyr::group_by(d, .data[["num"]])
101+
d2 <- tibble::as_tibble(d)
102+
d3 <- d
103+
dl <- list(ds1 = d1, ds2 = d2, ds3 = d3)
104+
edl <- list(ds1 = d, ds2 = d, ds3 = d)
105+
106+
dataset_lists <- list(
107+
dl1 = dl,
108+
dl2 = function() dl
109+
)
110+
111+
expected_dataset_lists <- list(
112+
dl1 = edl,
113+
dl2 = function() edl
114+
)
115+
116+
test_that("ungroup2df_datasets_dataset_list ungroups and transforms into data.frames datasets in a dataset_list" |>
117+
vdoc[["add_spec"]](c(specs$preprocessing$ungroup_datasets, specs$preprocessing$tibble2df)), {
118+
r <- ungroup2df_datasets_dataset_list(dl)
119+
expect_identical(r, edl)
120+
})
121+
122+
test_that("decorate_ungroup2df_datasets_dataset_list decorates a functions that returns a list of data.frames and ungroups and transforms into data.frames all datasets in the list" |>
123+
vdoc[["add_spec"]](c(specs$preprocessing$ungroup_datasets, specs$preprocessing$tibble2df)), { # nolintr
124+
f <- function() dl
125+
dec_f <- decorate_ungroup2df_datasets_dataset_list(f)
126+
e <- edl
127+
expect_identical(dec_f(), e)
128+
})
129+
130+
test_that("ungroup2df_datasets_dataset_lists applies decorators and transformations to dataset_lists" |>
131+
vdoc[["add_spec"]](c(specs$preprocessing$ungroup_datasets, specs$preprocessing$tibble2df)), {
132+
r <- ungroup2df_datasets_dataset_lists(dataset_lists)
133+
expect_identical(r[["dl1"]][["ds1"]], expected_dataset_lists[["dl1"]][["ds1"]])
134+
expect_identical(r[["dl1"]][["ds2"]], expected_dataset_lists[["dl1"]][["ds2"]])
135+
expect_identical(r[["dl2"]]()[["ds1"]], expected_dataset_lists[["dl2"]]()[["ds1"]])
136+
expect_identical(r[["dl2"]]()[["ds2"]], expected_dataset_lists[["dl2"]]()[["ds2"]])
137+
})
138+
139+
test_that("character variables are transformed into factors during run_app calls" |>
140+
vdoc[["add_spec"]](c(specs$preprocessing$ungroup_datasets, specs$preprocessing$tibble2df)), {
141+
r <- suppressMessages(
142+
suppressWarnings(
143+
run_app(dataset_lists, module_list = list(), filter_data = "ds1", filter_key = "num", .launch = FALSE)
144+
)
145+
)
146+
147+
expect_identical(r[["config"]][["data"]][["dl1"]][["ds1"]], expected_dataset_lists[["dl1"]][["ds1"]])
148+
expect_identical(r[["config"]][["data"]][["dl1"]][["ds2"]], expected_dataset_lists[["dl1"]][["ds2"]])
149+
expect_identical(r[["config"]][["data"]][["dl2"]]()[["ds1"]], expected_dataset_lists[["dl2"]]()[["ds1"]])
150+
expect_identical(r[["config"]][["data"]][["dl2"]]()[["ds2"]], expected_dataset_lists[["dl2"]]()[["ds2"]])
151+
})
152+
})

0 commit comments

Comments
 (0)