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

493 FilteredDatasetDefault class #497

Merged
merged 49 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5fd7a9b
🍕
gogonzo Nov 22, 2023
e82cb16
Merge branch 'main' into refactor
gogonzo Dec 4, 2023
6af3716
empty
gogonzo Dec 7, 2023
d6cd5ca
update
gogonzo Dec 7, 2023
82ef0f0
rephrase NEWS entry
gogonzo Dec 7, 2023
8afd3ce
@kartikeyakirar
gogonzo Dec 7, 2023
91224a8
rename DefaultFilteredDataset to DataframeFiltredDataset
Dec 8, 2023
1d8210c
add section titles in DataframeFilteredDataset
Dec 8, 2023
dbb1f4e
add constructor wrapper for new class
Dec 8, 2023
790dab3
unrelated bugfix
Dec 8, 2023
e4869dd
Merge branch 'main' into 493_FilteredDatasetDefault@main
Dec 11, 2023
c2797b7
modify FilteredData format method
Dec 11, 2023
43cead0
remove type checks from FilteredData set_dataset
Dec 11, 2023
f17ba6d
remove duplicate NEWS
Dec 11, 2023
250a84b
add new class DefaultFilteredDataset
Dec 11, 2023
a74e48f
trim constructor arguments
Dec 11, 2023
56a1629
add documentation
Dec 11, 2023
7d217c3
amend NEWS
Dec 11, 2023
9dd6085
update docs
Dec 11, 2023
8c5192c
expand unit tests
Dec 11, 2023
fa8d48e
rename test file
Dec 11, 2023
8a77d2b
add unit tests for the new class
Dec 11, 2023
d99b11d
adjust unit tests for FilteredData
Dec 11, 2023
740c020
more unit tests for the new class
Dec 11, 2023
a7b5434
editing
Dec 11, 2023
75526f6
adjust format for DefaultFilteredDataset
Dec 11, 2023
d66ae7c
remove skips
Dec 12, 2023
9e538e3
fix headers
Dec 12, 2023
b90af52
modify FilteredData format method
Dec 12, 2023
cadbbc1
adjust unit tests for FilteredData format
Dec 12, 2023
2ad0508
add trimming lines to DefaultFilteredDataset method
Dec 12, 2023
4299ccb
add return value in get_filter_overview method
Dec 12, 2023
28eca01
Merge 4299ccb85e1511445c5595fa55d1475bc5b4a785 into 950c92ef1e68ba196…
chlebowa Dec 12, 2023
07c54e7
[skip actions] Restyle files
github-actions[bot] Dec 12, 2023
0b01e5e
fix unit tets
Dec 12, 2023
d0e0a09
linter
Dec 12, 2023
0826a3f
Merge d0e0a09a1417334ce783d532f2a254a36eb72082 into 950c92ef1e68ba196…
chlebowa Dec 12, 2023
a68db80
[skip actions] Restyle files
github-actions[bot] Dec 12, 2023
448fd19
trigger
Dec 12, 2023
baa6c24
better `apply`s
chlebowa Dec 12, 2023
6dedba0
add module uis to for DefaultFiltedDataset
Dec 12, 2023
4bc289d
Merge branch '493_FilteredDatasetDefault@main' of github.com:insights…
Dec 12, 2023
427df8e
Merge 4bc289da970e237cd67ab02dfdb09c262ad9235a into 950c92ef1e68ba196…
chlebowa Dec 12, 2023
496b582
[skip actions] Restyle files
github-actions[bot] Dec 12, 2023
9524c2e
trigger
Dec 12, 2023
138a2e0
Merge branch 'main' into 493_FilteredDatasetDefault@main
chlebowa Dec 13, 2023
caac65e
apply review comments
Dec 14, 2023
e48d076
fix unit tests
Dec 14, 2023
e748cbb
display unsupported data types in overview
gogonzo Dec 14, 2023
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ S3method(init_filter_states,data.frame)
S3method(init_filter_states,matrix)
S3method(init_filtered_dataset,MultiAssayExperiment)
S3method(init_filtered_dataset,data.frame)
S3method(init_filtered_dataset,default)
S3method(print,teal_slice)
S3method(print,teal_slices)
S3method(variable_types,DFrame)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* `TealData` object is no longer supported by `teal.slice`.
* `set_filter_state` no longer accepts a nested list. Use `teal_slices()` and `teal_slice()` instead.
* Renamed `FilteredDataset` subclass that handles `data.frame`s from `DefaultFilteredDataset` to `DataframeFilteredDataset`. Added new class `DefaultFilteredDataset` that will store any type of object. Filtering will is not supported.

### Miscellaneous

Expand Down
30 changes: 24 additions & 6 deletions R/FilteredData.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ FilteredData <- R6::R6Class( # nolint
#' @description
#' Initialize a `FilteredData` object
#' @param data_objects (`list`)
#' should named elements containing `data.frame` or `MultiAssayExperiment`.
#' Named list of data objects.
#' Names of the list will serve as `dataname`.
#' @param join_keys (`join_keys` or NULL) see [`teal.data::join_keys()`].
#'
Expand Down Expand Up @@ -232,7 +232,8 @@ FilteredData <- R6::R6Class( # nolint
private$get_filtered_dataset(dataname)$get_filter_overview()
}
)
dplyr::bind_rows(rows)
unssuported_idx <- vapply(rows, function(x) all(is.na(x[-1])), logical(1))
dplyr::bind_rows(c(rows[!unssuported_idx], rows[unssuported_idx]))
},

#' @description
Expand All @@ -254,7 +255,7 @@ FilteredData <- R6::R6Class( # nolint
#' If this data has a parent specified in the `join_keys` object stored in `private$join_keys`
#' then created `FilteredDataset` (child) gets linked with other `FilteredDataset` (parent).
#' "Child" dataset return filtered data then dependent on the reactive filtered data of the
#' "parent". See more in documentation of `parent` argument in `FilteredDatasetDefault` constructor.
#' "parent". See more in documentation of `parent` argument in `DataframeFilteredDataset` constructor.
#'
#' @param data (`data.frame`, `MultiAssayExperiment`)\cr
#' data to be filtered.
Expand All @@ -265,7 +266,6 @@ FilteredData <- R6::R6Class( # nolint
#' @return (`self`) invisibly this `FilteredData`
#'
set_dataset = function(data, dataname) {
checkmate::assert_multi_class(data, classes = c("data.frame", "MultiAssayExperiment"))
checkmate::assert_string(dataname)
logger::log_trace("FilteredData$set_dataset setting dataset, name: { dataname }")
# to include it nicely in the Show R Code;
Expand Down Expand Up @@ -337,10 +337,16 @@ FilteredData <- R6::R6Class( # nolint
#' @return `character(1)` the formatted string
#'
format = function(show_all = FALSE, trim_lines = TRUE) {
datasets <- lapply(self$datanames(), private$get_filtered_dataset)
ind <- vapply(datasets, inherits, logical(1L), what = "DefaultFilteredDataset")
states <- do.call(c, lapply(datasets[!ind], function(ds) ds$get_filter_state()))
states_fmt <- format(states, show_all = show_all, trim_lines = trim_lines)
holders_fmt <- vapply(datasets[ind], format, character(1L), show_all = show_all, trim_lines = trim_lines)

sprintf(
"%s:\n%s",
class(self)[1],
format(self$get_filter_state(), show_all = show_all, trim_lines = trim_lines)
paste(c(states_fmt, holders_fmt), collapse = "\n")
)
},

Expand Down Expand Up @@ -830,7 +836,19 @@ FilteredData <- R6::R6Class( # nolint
function(x) {
tags$tr(
tagList(
lapply(x, tags$td)
tags$td(
if (all(x[-1] == "")) {
icon(
name = "exclamation-triangle",
title = "Unsupported dataset",
`data-container` = "body",
`data-toggle` = "popover",
`data-content` = "object not supported by the filter panel"
)
},
x[1]
),
lapply(x[-1], tags$td)
)
)
}
Expand Down
20 changes: 18 additions & 2 deletions R/FilteredDataset-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @keywords internal
#' @examples
#' # DefaultFilteredDataset example
#' # DataframeFilteredDataset example
#' iris_fd <- teal.slice:::init_filtered_dataset(iris, dataname = "iris")
#' app <- shinyApp(
#' ui = fluidPage(
Expand Down Expand Up @@ -89,7 +89,7 @@ init_filtered_dataset.data.frame <- function(dataset, # nolint
parent = NULL,
join_keys = character(0),
label = attr(dataset, "label")) {
DefaultFilteredDataset$new(
DataframeFilteredDataset$new(
dataset = dataset,
dataname = dataname,
keys = keys,
Expand Down Expand Up @@ -119,3 +119,19 @@ init_filtered_dataset.MultiAssayExperiment <- function(dataset, # nolint
label = label
)
}

#' @keywords internal
#' @export
init_filtered_dataset.default <- function(dataset, # nolint
dataname,
keys, # ignored
parent_name, # ignored
parent, # ignored
join_keys, # ignored
label = attr(dataset, "label")) {
DefaultFilteredDataset$new(
dataset = dataset,
dataname = dataname,
label = label
)
}
Loading