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

Refactor #440

Closed
wants to merge 9 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 @@ -21,8 +21,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,teal_data)
S3method(init_filtered_dataset,MultiAssayExperiment)
S3method(init_filtered_dataset,data.frame)
S3method(print,teal_slice)
Expand Down
34 changes: 12 additions & 22 deletions R/FilteredData-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,26 @@ init_filtered_data <- function(x, join_keys, code, check) {

#' @keywords internal
#' @export
init_filtered_data.TealData <- function(x, # nolint
join_keys = x$get_join_keys(),
code = x$get_code_class(),
check = x$get_check()) {
data_objects <- lapply(
x$get_datanames(),
function(dataname) {
dataset <- x$get_dataset(dataname)
list(
dataset = dataset$get_raw_data(),
metadata = dataset$get_metadata(),
label = dataset$get_dataset_label()
)
}
)
names(data_objects) <- x$get_datanames()

init_filtered_data(
x = data_objects,
join_keys = join_keys,
code = code,
init_filtered_data.teal_data <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint
checkmate::assert_class(code, "CodeClass", null.ok = TRUE)
checkmate::assert_class(join_keys, "JoinKeys")
checkmate::assert_flag(check)
FilteredData$new(
as.list(x@env),
join_keys = x@join_keys,
code = teal.data:::CodeClass$new(
code = paste(teal.code::get_code(x), collapse = "\n"),
dataname = teal.data::get_dataname(x)
),
check = check
)
}


#' @keywords internal
#' @export
init_filtered_data.default <- function(x, join_keys = teal.data::join_keys(), code = NULL, check = FALSE) { # nolint
checkmate::assert_list(x, any.missing = FALSE, names = "unique")
mapply(validate_dataset_args, x, names(x))
checkmate::assert_class(code, "CodeClass", null.ok = TRUE)
checkmate::assert_class(join_keys, "JoinKeys")
checkmate::assert_flag(check)
Expand Down
4 changes: 2 additions & 2 deletions R/FilteredData.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ FilteredData <- R6::R6Class( # nolint

for (dataname in ordered_datanames) {
ds_object <- data_objects[[dataname]]
validate_dataset_args(ds_object, dataname)
if (inherits(ds_object, c("data.frame", "MultiAssayExperiment"))) {
self$set_dataset(
data = ds_object,
Expand All @@ -104,6 +103,7 @@ FilteredData <- R6::R6Class( # nolint
} else {
# custom support for TealData object which pass metadata and label also
# see init_filtered_data.TealData
validate_dataset_args(ds_object, dataname)
self$set_dataset(
data = ds_object$dataset,
dataname = dataname,
Expand Down Expand Up @@ -327,7 +327,7 @@ FilteredData <- R6::R6Class( # nolint
#' Label to describe the dataset
#' @return (`self`) invisibly this `FilteredData`
#'
set_dataset = function(data, dataname, metadata, label) {
set_dataset = function(data, dataname, metadata = attr(data, "metadata"), label = attr(data, "label")) {
logger::log_trace("FilteredData$set_dataset setting dataset, name: { dataname }")
# to include it nicely in the Show R Code;
# the UI also uses `datanames` in ids, so no whitespaces allowed
Expand Down
7 changes: 6 additions & 1 deletion man/FilteredData.Rd

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