Skip to content
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

use topological_sort for summary table datasets #1277

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions R/1.0_module_data_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,24 @@ get_filter_overview <- function(teal_data) {
simplify = FALSE
)

rows <- lapply(
child_parent <- sapply(
datanames,
function(i) teal.data::parent(joinkeys, i),
USE.NAMES = TRUE,
simplify = FALSE
)
ordered_datanames <- topological_sort(child_parent)
ordered_datanames <- intersect(ordered_datanames, datanames)

rows <- lapply(
ordered_datanames,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd apply this to teal_data_datanames function so that we keep this order consistent in whole teal application.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gogonzo do you mean teal.data::datanames() ? https://github.com/insightsengineering/teal.data/blob/main/R/teal_data-datanames.R#L34

Sure, that would make sense. So each time datanames(teal_data) is called we already get names in the topological sort order. So let's abandon this branch and I'll provide a PR in teal.data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean teal:::teal_data_datanames

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a small PR in teal.data package. Still WIP. Asked @averissimo for the review insightsengineering/teal.data#318

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore my PR, I will investigate teal:::teal_data_datanames

function(dataname) {
parent <- teal.data::parent(joinkeys, dataname)

# todo: what should we display for a parent dataset?
# - Obs and Subjects
# - Obs only
# - Subjects only
# todo: summary table should be ordered by topological order
# todo (for later): summary table should be displayed in a way that child datasets
# are indented under their parent dataset to form a tree structure
subject_keys <- if (length(parent) > 0) {
Expand Down Expand Up @@ -260,3 +268,17 @@ get_object_filter_overview_MultiAssayExperiment <- function(filtered_data, # nol
experiment_info <- cbind(experiment_obs_info[, c("dataname", "obs", "obs_filtered")], experiment_subjects_info)
rbind(mae_info, experiment_info)
}


#' @inherit teal.data::topological_sort description details params title
#' @examples
#' # use non-exported function from teal.slice
#' topological_sort <- getFromNamespace("topological_sort", "teal.slice")
#'
#' topological_sort(list(A = c(), B = c("A"), C = c("B"), D = c("A")))
#' topological_sort(list(D = c("A"), A = c(), B = c("A"), C = c("B")))
#' topological_sort(list(D = c("A"), B = c("A"), C = c("B"), A = c()))
#' @keywords internal
topological_sort <- function(graph) {
utils::getFromNamespace("topological_sort", ns = "teal.data")(graph)
}
27 changes: 27 additions & 0 deletions man/topological_sort.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 48 additions & 6 deletions tests/testthat/test-shinytest2-data_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ testthat::test_that("e2e: data summary is displayed with 2 columns data without
app$stop()
})

testthat::test_that("e2e: data summary displays datasets by topological_sort of join_keys", {
skip_if_too_deep(5)

data <- teal.data::teal_data(mtcars1 = mtcars, mtcars2 = data.frame(am = c(0, 1), test = c("a", "b")))

teal.data::join_keys(data) <- teal.data::join_keys(
teal.data::join_key("mtcars2", "mtcars1", keys = c("am"))
)

app <- TealAppDriver$new(
data = data,
modules = example_module()
)

testthat::expect_identical(
testthat::expect_identical(
as.data.frame(app$get_active_data_summary_table())[["Data Name"]],
c("mtcars2", "mtcars1")
)
)

app$stop()
})

testthat::test_that("e2e: data summary is displayed with 3 columns for data with join keys", {
skip_if_too_deep(5)

Expand All @@ -53,9 +77,9 @@ testthat::test_that("e2e: data summary is displayed with 3 columns for data with
testthat::expect_identical(
as.data.frame(app$get_active_data_summary_table()),
data.frame(
`Data Name` = c("mtcars1", "mtcars2"),
Obs = c("32/32", "2/2"),
Subjects = c("2/2", "2/2"),
`Data Name` = c("mtcars2", "mtcars1"),
Obs = c("2/2", "32/32"),
Subjects = c("", "2/2"),
check.names = FALSE
)
)
Expand Down Expand Up @@ -97,14 +121,32 @@ testthat::test_that(
data.frame(
`Data Name` = c(
"CO2", "iris", "miniACC", "- RNASeq2GeneNorm", "- gistict", "- RPPAArray", "- Mutations", "- miRNASeqGene",
"mtcars1", "mtcars2", "factors"
"mtcars2", "mtcars1", "factors"
),
Obs = c("84/84", "150/150", "", "198/198", "198/198", "33/33", "97/97", "471/471", "32/32", "2/2", ""),
Subjects = c("", "", "92/92", "79/79", "90/90", "46/46", "90/90", "80/80", "2/2", "2/2", ""),
Obs = c("84/84", "150/150", "", "198/198", "198/198", "33/33", "97/97", "471/471", "2/2", "32/32", ""),
Subjects = c("", "", "92/92", "79/79", "90/90", "46/46", "90/90", "80/80", "", "2/2", ""),
check.names = FALSE
)
)

app$stop()
}
)

testthat::test_that("e2e: data summary displays datasets by datanames() order if no join_keys", {
skip_if_too_deep(5)

data <- teal.data::teal_data(mtcars1 = mtcars, mtcars2 = data.frame(am = c(0, 1), test = c("a", "b")))

app <- TealAppDriver$new(
data = data,
modules = example_module()
)

testthat::expect_identical(
as.data.frame(app$get_active_data_summary_table())[["Data Name"]],
c("mtcars1", "mtcars2")
)

app$stop()
})
Loading