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

Tdata in tealdata@main #212

Closed
wants to merge 7 commits into from
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
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ S3method(init_filter_states,MultiAssayExperiment)
S3method(init_filter_states,SummarizedExperiment)
S3method(init_filter_states,data.frame)
S3method(init_filter_states,matrix)
S3method(init_filtered_data,TealData)
S3method(init_filtered_data,default)
S3method(init_filtered_data,tdata)
S3method(init_filtered_dataset,MultiAssayExperiment)
S3method(init_filtered_dataset,data.frame)
S3method(resolve_state,default)
Expand Down
59 changes: 33 additions & 26 deletions R/FilteredData-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ init_filtered_data <- function(x, join_keys, code, cdisc, check) {

#' @keywords internal
#' @export
init_filtered_data.TealData <- function(x, # nolint
join_keys = x$get_join_keys(),
code = x$get_code_class(),
cdisc = FALSE,
check = x$get_check()) {
init_filtered_data.tdata <- function(x, # nolint
join_keys = attr(x, "join_keys"),
code = attr(x, "code")(),
cdisc = FALSE,
check = attr(x, "check")) {
cdisc <- length(join_keys$get_parents()) > 0
data_objects <- lapply(x$get_datanames(), function(dataname) {
dataset <- x$get_dataset(dataname)
data_objects <- lapply(names(x), function(dataname) {
dataset <- x[[dataname]]()

parent <- if (cdisc) join_keys$get_parent(dataname) else NULL

return_list <- list(
dataset = dataset$get_raw_data(),
keys = dataset$get_keys(),
metadata = dataset$get_metadata(),
label = dataset$get_dataset_label()
dataset = dataset,
keys = join_keys$get(dataname, dataname),
metadata = teal.data::get_metadata(x, dataname),
label = attr(x, "label")[["dataname"]]
)

if (cdisc) return_list[["parent"]] <- parent
return_list
})

names(data_objects) <- x$get_datanames()
names(data_objects) <- names(x)

init_filtered_data(
x = data_objects,
Expand Down Expand Up @@ -184,26 +184,33 @@ eval_expr_with_msg <- function(expr, env) {
#' )
#'
#' server <- function(input, output, session) {
#' observeEvent(input$hide_content,
#' {
#' shinyjs::hide("content")
#' toggle_icon("toggle_content", c("fa-angle-down", "fa-angle-right"), one_way = TRUE)
#' },
#' ignoreInit = TRUE
#' )
#'
#' observeEvent(input$hide_content, {
#' shinyjs::hide("content")
#' toggle_icon("toggle_content", c("fa-angle-down", "fa-angle-right"), one_way = TRUE)
#' }, ignoreInit = TRUE)
#'
#' observeEvent(input$show_content, {
#' shinyjs::show("content")
#' toggle_icon("toggle_content", c("fa-angle-right", "fa-angle-down"), one_way = TRUE)
#' }, ignoreInit = TRUE)
#' observeEvent(input$show_content,
#' {
#' shinyjs::show("content")
#' toggle_icon("toggle_content", c("fa-angle-right", "fa-angle-down"), one_way = TRUE)
#' },
#' ignoreInit = TRUE
#' )
#'
#' observeEvent(input$toggle_content, {
#' shinyjs::toggle("content")
#' toggle_icon("toggle_content", c("fa-angle-right", "fa-angle-down"))
#' }, ignoreInit = TRUE)
#' observeEvent(input$toggle_content,
#' {
#' shinyjs::toggle("content")
#' toggle_icon("toggle_content", c("fa-angle-right", "fa-angle-down"))
#' },
#' ignoreInit = TRUE
#' )
#'
#' output$printout <- renderPrint({
#' head(faithful, 10)
#' })
#'
#' }
#'
#' if (interactive()) {
Expand Down
35 changes: 21 additions & 14 deletions man/toggle_button.Rd

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

14 changes: 7 additions & 7 deletions tests/testthat/test-CDISCFilteredData.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ get_cdisc_filtered_data <- function() {
data <- teal.data::cdisc_data(
teal.data::cdisc_dataset("ADSL", adsl),
teal.data::cdisc_dataset("ADAE", adae)
)
)$get_tdata()

list(ds = init_filtered_data(data), adsl = adsl, adae = adae)
list(ds = isolate(init_filtered_data(data)), adsl = adsl, adae = adae)
}

testthat::test_that("load and set_datasets", {
Expand Down Expand Up @@ -104,7 +104,7 @@ testthat::test_that("get_filterable_varnames does not return child duplicates",
)
data <- teal.data::cdisc_data(adsl, child)

fd <- init_filtered_data(data)
fd <- isolate(init_filtered_data(data$get_tdata()))
testthat::expect_identical(
fd$get_filterable_varnames("ADTTE"),
c("PARAMCD", "c")
Expand All @@ -124,7 +124,7 @@ testthat::test_that("get_filterable_varnames does not return child non-filterabl
)
data <- teal.data::cdisc_data(adsl, child)

fd <- init_filtered_data(data)
fd <- isolate(init_filtered_data(data$get_tdata()))

fd$set_filterable_varnames("ADTTE", c("PARAMCD", "STUDYID"))
testthat::expect_identical(
Expand All @@ -144,7 +144,7 @@ testthat::test_that("get_filterable_varnames return all filterable variables fro
)
data <- teal.data::cdisc_data(adsl, child)

fd <- init_filtered_data(data)
fd <- isolate(init_filtered_data(data$get_tdata()))

testthat::expect_identical(
fd$get_filterable_varnames("ADSL"),
Expand All @@ -170,7 +170,7 @@ testthat::test_that("get_filterable_varnames does not return duplicates from par
)
data <- teal.data::cdisc_data(adsl, child)

fd <- init_filtered_data(data)
fd <- isolate(init_filtered_data(data$get_tdata()))

fd$set_filterable_varnames("ADSL", c("a", "b"))

Expand All @@ -196,7 +196,7 @@ testthat::test_that(
)
data <- teal.data::cdisc_data(adsl, child)

fd <- init_filtered_data(data)
fd <- isolate(init_filtered_data(data$get_tdata()))
testthat::expect_warning(
shiny::isolate(fd$set_filter_state(list(ADTTE = list(USUBJID = "1")))),
"These columns filters were excluded: USUBJID from dataset ADTTE"
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-init_filtered_data.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
testthat::test_that("init_filtered_data accepts a TealData object", {
testthat::test_that("init_filtered_data accepts a tdata object of a tealData object", {
teal_data <- teal.data::teal_data(teal.data::dataset(dataname = "iris", x = iris))
testthat::expect_no_error(init_filtered_data(teal_data))
testthat::expect_no_error(isolate(init_filtered_data(teal_data$get_tdata())))
})

testthat::test_that("init_filtered_data accepts a CDISCTealData with mixed CDISC and Dataset", {
Expand All @@ -9,7 +9,7 @@ testthat::test_that("init_filtered_data accepts a CDISCTealData with mixed CDISC
teal.data::dataset(dataname = "iris", x = iris),
teal.data::cdisc_dataset("ADSL", adsl)
)
testthat::expect_no_error(init_filtered_data(teal_data))
testthat::expect_no_error(isolate(init_filtered_data(teal_data$get_tdata())))
})

testthat::test_that("init_filtered_data accepts a list of `data.frame` objects", {
Expand Down