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

Introduce teal_data class #470

Merged
merged 22 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
10 changes: 8 additions & 2 deletions R/FilteredData-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ init_filtered_data.TealData <- function(x, # nolint
join_keys = x$get_join_keys(),
code = x$get_code_class(),
check = x$get_check()) {
lifecycle::deprecate_warn(
when = "0.4.1",
"init_filtered_data(
x = 'constructor based on TealData is deprecated and will be removed soon.
Please use generic init_filtered_data and specify all arguments directly.'
)"
)
data_objects <- lapply(
x$get_datanames(),
function(dataname) {
Expand All @@ -55,7 +62,6 @@ init_filtered_data.TealData <- function(x, # nolint
#' @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 All @@ -80,7 +86,7 @@ validate_dataset_args <- function(dataset_args, dataname) {

checkmate::assert_subset(names(dataset_args), choices = allowed_names)
checkmate::assert_multi_class(dataset_args[["dataset"]], classes = c("data.frame", "MultiAssayExperiment"))
teal.data::validate_metadata(dataset_args[["metadata"]])
checkmate::assert_list(dataset_args[["metadata"]], names = "named", null.ok = TRUE)
checkmate::assert_character(dataset_args[["label"]], null.ok = TRUE, min.len = 0, max.len = 1)
}

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
2 changes: 1 addition & 1 deletion R/FilteredDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ FilteredDataset <- R6::R6Class( # nolint
check_simple_name(dataname)
checkmate::assert_character(keys, any.missing = FALSE)
checkmate::assert_character(label, null.ok = TRUE)
teal.data::validate_metadata(metadata)
checkmate::assert_list(metadata, names = "named", null.ok = TRUE)

logger::log_trace("Instantiating { class(self)[1] }, dataname: { dataname }")
private$dataset <- dataset
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.