Skip to content

Commit

Permalink
fix r cmd check (except vignettes)
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Nov 30, 2023
1 parent 6afeae7 commit 021678d
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 259 deletions.
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export(TealReportCard)
export(as.teal_slices)
export(as_tdata)
export(example_module)
export(get_code.tdata)
export(get_code_tdata)
export(get_metadata)
export(init)
Expand Down Expand Up @@ -47,6 +46,6 @@ import(shiny)
import(teal.data)
import(teal.slice)
import(teal.transform)
importFrom(lifecycle,deprecate_soft)
importFrom(lifecycle,badge)
importFrom(magrittr,"%>%")
importFrom(stats,setNames)
35 changes: 18 additions & 17 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@
#' End-users: This is the most important function for you to start a
#' teal app that is composed out of teal modules.
#'
#' @param data (`TealData` or `TealDataset` or `TealDatasetConnector` or `list` or `data.frame`
#' or `MultiAssayExperiment`, `teal_data`, `teal_data_module`)\cr
#' `R6` object as returned by [teal.data::cdisc_data()], [teal.data::teal_data()],
#' [teal.data::cdisc_dataset()], [teal.data::dataset()], [teal.data::dataset_connector()] or
#' [teal.data::cdisc_dataset_connector()] or [teal_data_module()] or a single `data.frame` or
#' a `MultiAssayExperiment`
#' or a list of the previous objects or function returning a named list.
#' NOTE: teal does not guarantee reproducibility of the code when names of the list elements
#' do not match the original object names. To ensure reproducibility please use [teal.data::teal_data()]
#' or [teal.data::cdisc_data()] with `check = TRUE` enabled.
#' @param data (`teal_data`, `teal_data_module`, `named list`)\cr
#' `teal_data` object as returned by [teal.data::teal_data()] or
#' `teal_data_modules` or simply a list of a named list of objects
#' (`data.frame` or `MultiAssayExperiment`).
#' @param modules (`list`, `teal_modules` or `teal_module`)\cr
#' nested list of `teal_modules` or `teal_module` objects or a single
#' `teal_modules` or `teal_module` object. These are the specific output modules which
Expand Down Expand Up @@ -108,11 +102,22 @@ init <- function(data,
footer = tags$p(),
id = character(0)) {
logger::log_trace("init initializing teal app with: data ({ class(data)[1] }).")
if (!inherits(data, c("TealData", "teal_data", "teal_data_module"))) {
data <- teal.data::to_relational_data(data = data)
if (is.list(data)) {
checkmate::assert_list(data, names = "named")
data <- do.call(teal.data::teal_data, data)
}
if (inherits(data, "TealData")) {
lifecycle::deprecate_stop(
when = "0.99.0",
what = "init(data)",
paste(
"TealData is no longer supported. Use teal_data() instead.",
"Please follow migration instructions https://github.com/insightsengineering/teal/discussions/988."
)
)
}

checkmate::assert_multi_class(data, c("TealData", "teal_data", "teal_data_module"))
checkmate::assert_multi_class(data, c("teal_data", "teal_data_module"))
checkmate::assert_multi_class(modules, c("teal_module", "list", "teal_modules"))
checkmate::assert_string(title, null.ok = TRUE)
checkmate::assert(
Expand Down Expand Up @@ -215,10 +220,6 @@ init <- function(data,
landing_module <- landing[[1L]]
do.call(landing_module$server, c(list(id = "landing_module_shiny_id"), landing_module$server_args))
}
if (inherits(data, "TealDataAbstract")) {
# copy TealData so that load won't be shared between the session
data <- data$copy(deep = TRUE)
}
filter <- deep_copy_filter(filter)
srv_teal_with_splash(id = id, data = data, modules = modules, filter = filter)
}
Expand Down
40 changes: 3 additions & 37 deletions R/module_teal_with_splash.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ui_teal_with_splash <- function(id,
title,
header = tags$p("Add Title Here"),
footer = tags$p("Add Footer Here")) {
checkmate::assert_multi_class(data, c("TealData", "teal_data", "teal_data_module"))
checkmate::assert_multi_class(data, c("teal_data", "teal_data_module"))
ns <- NS(id)

# Startup splash screen for delayed loading
Expand All @@ -33,11 +33,6 @@ ui_teal_with_splash <- function(id,
data$ui(ns("teal_data_module"))
} else if (inherits(data, "teal_data")) {
div()
} else if (inherits(data, "TealDataAbstract") && teal.data::is_pulled(data)) {
div()
} else {
message("App was initialized with delayed data loading.")
data$get_ui(ns("startapp_module"))
}
ui_teal(
id = ns("teal"),
Expand All @@ -63,7 +58,7 @@ ui_teal_with_splash <- function(id,
#' If data is not loaded yet, `reactive` returns `NULL`.
#' @export
srv_teal_with_splash <- function(id, data, modules, filter = teal_slices()) {
checkmate::check_multi_class(data, c("TealData", "teal_data", "teal_data_module"))
checkmate::check_multi_class(data, c("teal_data", "teal_data_module"))

moduleServer(id, function(input, output, session) {
logger::log_trace("srv_teal_with_splash initializing module with data.")
Expand All @@ -82,41 +77,13 @@ srv_teal_with_splash <- function(id, data, modules, filter = teal_slices()) {
data
} else if (inherits(data, "teal_data")) {
reactiveVal(data)
} else if (inherits(data, "TealDataAbstract") && teal.data::is_pulled(data)) {
new_data <- do.call(
teal.data::teal_data,
c(
lapply(data$get_datasets(), function(x) x$get_raw_data()),
list(code = data$get_code()),
list(join_keys = teal.data::join_keys(data))
)
)
reactiveVal(new_data) # will trigger by setting it
} else {
raw_data_old <- data$get_server()(id = "startapp_module")
raw_data <- reactive({
data <- raw_data_old()
if (!is.null(data)) {
# raw_data is a reactive which returns data only when submit button clicked
# otherwise it returns NULL
do.call(
teal.data::teal_data,
c(
lapply(data$get_datasets(), function(x) x$get_raw_data()),
list(code = data$get_code()),
list(join_keys = teal.data::join_keys(data))
)
)
}
})
raw_data
}

teal_data_rv_validate <- reactive({
# custom module can return error
data <- tryCatch(teal_data_rv(), error = function(e) e)

# there is an empty reactive event on init!
# there is an empty reactive cycle on init!
if (inherits(data, "shiny.silent.error") && identical(data$message, "")) {
return(NULL)
}
Expand Down Expand Up @@ -184,7 +151,6 @@ srv_teal_with_splash <- function(id, data, modules, filter = teal_slices()) {
})



res <- srv_teal(id = "teal", modules = modules, teal_data_rv = teal_data_rv_validate, filter = filter)
logger::log_trace("srv_teal_with_splash initialized module with data.")
return(res)
Expand Down
23 changes: 11 additions & 12 deletions R/tdata.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' Create a `tdata` Object
#'
#' @description `r lifecycle::badge("deprecated")`
#' Create a new object called `tdata` which contains `data`, a `reactive` list of data.frames
#' (or `MultiAssayExperiment`), with attributes:
#' \itemize{
Expand Down Expand Up @@ -37,13 +38,21 @@
#' isolate(data[["iris"]]())
#'
#' # Get code
#' isolate(get_code(data))
#' isolate(get_code_tdata(data))
#'
#' # Get metadata
#' get_metadata(data, "iris")
#'
#' @export
new_tdata <- function(data, code = "", join_keys = NULL, metadata = NULL) {
lifecycle::deprecate_soft(
when = "0.99.0",
what = "tdata()",
details = paste(
"tdata is deprecated and will be removed in the next release. Use `teal_data` instead.\n",
"Please follow migration instructions https://github.com/insightsengineering/teal/discussions/987."
)
)
checkmate::assert_list(
data,
any.missing = FALSE, names = "unique",
Expand All @@ -54,7 +63,6 @@ new_tdata <- function(data, code = "", join_keys = NULL, metadata = NULL) {

checkmate::assert_list(metadata, names = "unique", null.ok = TRUE)
checkmate::assert_subset(names(metadata), names(data))
for (m in metadata) teal.data::validate_metadata(m)

if (is.reactive(code)) {
isolate(checkmate::assert_class(code(), "character", .var.name = "code"))
Expand Down Expand Up @@ -104,15 +112,6 @@ tdata2env <- function(data) { # nolint
list2env(lapply(data, function(x) if (is.reactive(x)) x() else x))
}

#' @rdname tdata
#' @param x a `tdata` object
#' @param ... additional arguments for the generic
#' @export
get_code.tdata <- function(x, ...) { # nolint
# note teal.data which teal depends on defines the get_code method
attr(x, "code")()
}


#' Wrapper for `get_code.tdata`
#' This wrapper is to be used by downstream packages to extract the code of a `tdata` object
Expand All @@ -123,7 +122,7 @@ get_code.tdata <- function(x, ...) { # nolint
#' @export
get_code_tdata <- function(data) {
checkmate::assert_class(data, "tdata")
get_code(data)
attr(data, "code")()
}

#' Extract `join_keys` from `tdata`
Expand Down
4 changes: 2 additions & 2 deletions R/teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ magrittr::`%>%`
NULL

# Fix R CMD check notes
#' @importFrom lifecycle deprecate_soft
lifecycle::deprecate_soft
#' @importFrom lifecycle badge
lifecycle::badge
1 change: 1 addition & 0 deletions R/teal_data_module.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' Data module for `teal` applications
#'
#' @description `r lifecycle::badge("experimental")`
#' Creates `teal_data_module` object - a `shiny` module to supply or modify data in a `teal` application.
#'
#' This function creates a `shiny` module that allows for running data pre-processing code after the app starts.
Expand Down
2 changes: 1 addition & 1 deletion R/teal_slices.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
#' )
#'
#' app <- teal::init(
#' data = list(iris = iris, mtcars = mtcars),
#' modules = list(
#' module("module1"),
#' module("module2")
#' ),
#' data = list(iris, mtcars),
#' filter = filter
#' )
#'
Expand Down
14 changes: 4 additions & 10 deletions man/init.Rd

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

4 changes: 2 additions & 2 deletions man/reexports.Rd

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

14 changes: 4 additions & 10 deletions man/srv_teal_with_splash.Rd

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

10 changes: 2 additions & 8 deletions man/tdata.Rd

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

4 changes: 2 additions & 2 deletions man/teal_data_module.Rd

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

2 changes: 1 addition & 1 deletion man/teal_slices.Rd

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

14 changes: 4 additions & 10 deletions man/ui_teal_with_splash.Rd

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

Loading

0 comments on commit 021678d

Please sign in to comment.