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

999 set default datanames to ls(data@env) #1004

Merged
merged 24 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
929dddd
setting better default datanames
kartikeyakirar Dec 11, 2023
94e0aa8
add update_default_dataname function.
kartikeyakirar Dec 11, 2023
ce5f387
Merge 94e0aa8e1d863e7c92ee28c04d28bb216b316df6 into 982184d76cd002156…
kartikeyakirar Dec 11, 2023
8d949a0
[skip actions] Restyle files
github-actions[bot] Dec 11, 2023
fb08f9a
allowing everyting
kartikeyakirar Dec 11, 2023
49e5c64
styling
kartikeyakirar Dec 11, 2023
1e85bfc
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Dec 11, 2023
1a12b02
update Rd
kartikeyakirar Dec 11, 2023
9107b48
updated test.
kartikeyakirar Dec 11, 2023
5167ee3
fixing lintr
kartikeyakirar Dec 11, 2023
28afe0b
Merge branch 'main' into 999_default_dataname@main
kartikeyakirar Dec 12, 2023
56a5dcc
changes per suggestions
kartikeyakirar Dec 13, 2023
2decef3
additional tests
kartikeyakirar Dec 13, 2023
dd48dc2
suggestion (removing notification)
kartikeyakirar Dec 13, 2023
6866652
failing app on emapty object
kartikeyakirar Dec 13, 2023
bf1729d
Merge branch 'main' into 999_default_dataname@main
kartikeyakirar Dec 13, 2023
f391e86
Merge branch 'main' into 999_default_dataname@main
kartikeyakirar Dec 14, 2023
3504669
add wrapper teal_data_datanames
kartikeyakirar Dec 14, 2023
0eb8a2f
amend suggestions
kartikeyakirar Dec 14, 2023
bbbb575
fixing tests
kartikeyakirar Dec 14, 2023
77d0d0f
Update R/module_teal_with_splash.R
kartikeyakirar Dec 14, 2023
0596dee
amend suggestions
kartikeyakirar Dec 14, 2023
e7da94e
Merge branch 'main' into 999_default_dataname@main
kartikeyakirar Dec 18, 2023
f611e55
adding details
kartikeyakirar Dec 18, 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
4 changes: 1 addition & 3 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ init <- function(data,
}

if (inherits(data, "teal_data")) {
if (length(teal.data::datanames(data)) == 0) {
stop("`data` object has no datanames. Specify `datanames(data)` and try again.")
}
data <- update_default_dataname(data)

# in case of teal_data_module this check is postponed to the srv_teal_with_splash
is_modules_ok <- check_modules_datanames(modules, teal.data::datanames(data))
Expand Down
4 changes: 1 addition & 3 deletions R/module_teal_with_splash.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ srv_teal_with_splash <- function(id, data, modules, filter = teal_slices()) {
)
)

validate(need(teal.data::datanames(data), "Data has no datanames. Contact app developer."))


data <- update_default_dataname(data)
is_modules_ok <- check_modules_datanames(modules, teal.data::datanames(data))
validate(need(isTRUE(is_modules_ok), is_modules_ok))

Expand Down
24 changes: 24 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,27 @@ check_filter_datanames <- function(filters, datanames) {
TRUE
}
}

#' Retrieve Default Dataset Names from a Data Object
#'
#' This function extracts dataset names from a `teal_data` object. If the object has no predefined
#' dataset names, it fetches names from the object's environment for datasets of class `data.frame`
#' or `MultiAssayExperiment`.
#'
#' @param tealData (`teal_data`) object
#'
#' @return A `teal_data` object.
#' @keywords internal
update_default_dataname <- function(data) {
if (length(teal.data::datanames(data)) == 0) {
warning("`data` object has no datanames. Default datanames are specified from environment.")
datanames <- ls(data@env)
classes <- sapply(datanames, function(dn) class(data[[dn]]), simplify = "array")
valid_datanames <- datanames[classes %in% c("data.frame", "MultiAssayExperiment")]
if (length(valid_datanames) == 0) {
stop("Data environment does not contains valid data class. Contact app developer.")
}
kartikeyakirar marked this conversation as resolved.
Show resolved Hide resolved
teal.data::datanames(data) <- get_default_dataname(data)
}
data
}