Skip to content

Commit

Permalink
Skip tests/examples when packages in Suggest section are not installed (
Browse files Browse the repository at this point in the history
#518)

- Part of pre-release activities #506 (base branch for this PR is
`pre-release-cleanup@main`)
- Rationale on
insightsengineering/idr-tasks#713

### Changes description

- [x] Handles `@examples`
- with `@examplesIf requireNamespace("MultiAssayExperiment")` as
suggested
[here](https://indrajeetpatil.github.io/preventive-r-package-care/#/soft-dependency-hygiene)
  - Conditional clause replacing `miniACC` with empty data.frame
- [x] Skips tests that use {MAE} or {SE}
- [x] Skips tests that use {withr}

#### Discussions

- > That's not a reason to skip tests. MAE is in Suggests so installing
is the responsibility of the person who wants to run tests, i.e. not the
end user. If someone uses teal with MAE data, they most likely have the
package installed.
- Some generic tests and examples for `filter_state_api` are complex
cases that join together normal data frames with MAE
    - These could be broken down to 2 examples.
- If we merge this it also means tests using {withr} should be skipped
  - Seems silly, but necessary to be a complete compliance

WDYT?
  • Loading branch information
averissimo authored Jan 17, 2024
1 parent 99e53e5 commit 3220aac
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 20 deletions.
2 changes: 1 addition & 1 deletion R/FilteredData.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#' isolate(datasets$get_filter_state())
#' isolate(datasets$get_call("iris"))
#' isolate(datasets$get_call("mtcars"))
#'
#' @examplesIf requireNamespace("MultiAssayExperiment")
#' ### set_filter_state
#'
#' utils::data(miniACC, package = "MultiAssayExperiment")
Expand Down
1 change: 1 addition & 0 deletions R/FilteredDataset-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#' shinyApp(ui, server)
#' }
#'
#' @examplesIf requireNamespace("MultiAssayExperiment")
#' # MAEFilteredDataset example
#' library(MultiAssayExperiment)
#' data(miniACC)
Expand Down
2 changes: 1 addition & 1 deletion R/FilteredDatasetMAE.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#' @title `MAEFilteredDataset` `R6` class
#' @keywords internal
#' @examples
#' @examplesIf requireNamespace("MultiAssayExperiment")
#' # use non-exported function from teal.slice
#' MAEFilteredDataset <- getFromNamespace("MAEFilteredDataset", "teal.slice")
#'
Expand Down
46 changes: 40 additions & 6 deletions R/filter_panel_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,53 @@
#' @seealso [`teal_slice`]
#'
#' @examples
#' library(MultiAssayExperiment)
#' data(miniACC)
#'
#' datasets <- init_filtered_data(
#' x = list(
#' iris = list(dataset = iris),
#' mae = list(dataset = miniACC)
#' mtcars = list(dataset = mtcars)
#' )
#' )
#' fs <- teal_slices(
#' teal_slice(dataname = "iris", varname = "Species", selected = c("setosa", "versicolor")),
#' teal_slice(dataname = "iris", varname = "Sepal.Length", selected = c(5.1, 6.4)),
#' teal_slice(dataname = "mtcars", varname = "gear", selected = c(4, 5)),
#' teal_slice(dataname = "mtcars", varname = "carb", selected = c(4, 10))
#' )
#'
#' # set initial filter state
#' set_filter_state(datasets, filter = fs)
#'
#' # get filter state
#' get_filter_state(datasets)
#'
#' # modify filter state
#' set_filter_state(
#' datasets,
#' teal_slices(
#' teal_slice(dataname = "iris", varname = "Species", selected = "setosa", keep_na = TRUE)
#' )
#' )
#'
#' # remove specific filters
#' remove_filter_state(
#' datasets,
#' teal_slices(
#' teal_slice(dataname = "iris", varname = "Species"),
#' teal_slice(dataname = "mtcars", varname = "gear"),
#' teal_slice(dataname = "mtcars", varname = "carb")
#' )
#' )
#'
#' # remove all states
#' clear_filter_states(datasets)
#' @examplesIf requireNamespace("MultiAssayExperiment")
#'
#' # Requires MultiAssayExperiment from Bioconductor
#' library(MultiAssayExperiment)
#' data(miniACC)
#'
#' datasets <- init_filtered_data(x = list(mae = list(dataset = miniAcc)))
#' fs <- teal_slices(
#' teal_slice(
#' dataname = "mae", varname = "years_to_birth", selected = c(30, 50),
#' keep_na = TRUE, keep_inf = FALSE
Expand Down Expand Up @@ -63,15 +98,14 @@
#' set_filter_state(
#' datasets,
#' teal_slices(
#' teal_slice(dataname = "iris", varname = "Species", selected = "setosa", keep_na = TRUE)
#' teal_slice(dataname = "mae", varname = "years_to_birth", selected = c(40, 60))
#' )
#' )
#'
#' # remove specific filters
#' remove_filter_state(
#' datasets,
#' teal_slices(
#' teal_slice(dataname = "iris", varname = "Species"),
#' teal_slice(dataname = "mae", varname = "years_to_birth"),
#' teal_slice(dataname = "mae", varname = "vital_status")
#' )
Expand Down
4 changes: 2 additions & 2 deletions man/FilteredData.Rd

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

3 changes: 2 additions & 1 deletion man/MAEFilteredDataset.Rd

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

48 changes: 42 additions & 6 deletions man/filter_state_api.Rd

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

3 changes: 2 additions & 1 deletion man/init_filtered_dataset.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-FilteredData.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# initialize ----
testthat::test_that("constructor accepts all types of datasets", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")

testthat::expect_no_error(FilteredData$new(list("logical" = c(TRUE, FALSE))))
Expand Down Expand Up @@ -718,6 +719,8 @@ testthat::test_that("srv_active - clicking remove_all button clears filters", {

# get_filter_count
testthat::test_that("get_filter_count properly tallies active filter states", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
test_class <- R6::R6Class(
classname = "test_class",
inherit = FilteredData,
Expand Down Expand Up @@ -753,6 +756,8 @@ testthat::test_that("get_filter_count properly tallies active filter states for
}
)
)
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
datasets <- test_class$new(
list(
iris = list(dataset = iris),
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-MAEFilterStates.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
utils::data(miniACC, package = "MultiAssayExperiment")

# initialize ----
testthat::test_that("constructor accepts a MultiAssayExperiment", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_no_error(
MAEFilterStates$new(data = miniACC, dataname = "miniACC")
)
Expand All @@ -13,6 +13,8 @@ testthat::test_that("constructor accepts a MultiAssayExperiment", {

# get_filter_state ----
testthat::test_that("get_filter_state returns `teal_slices` with include_varname by default and count_type=none", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filter_states <- MAEFilterStates$new(data = miniACC, dataname = "miniACC")
fs <- teal_slices(
count_type = "none",
Expand All @@ -27,6 +29,8 @@ testthat::test_that("get_filter_state returns `teal_slices` with include_varname

# get_call ----
testthat::test_that("get_call returns subsetByColData call with varnames prefixed by dataname$", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filter_states <- MAEFilterStates$new(data = miniACC, dataname = "miniacc")
filter_states$set_filter_state(
teal_slices(
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-MAEFilteredDataset.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# initialize ----
testthat::test_that("constructor accepts a MultiAssayExperiment object", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
testthat::expect_no_error(MAEFilteredDataset$new(dataset = miniACC, dataname = "miniACC"))
testthat::expect_error(
Expand All @@ -13,6 +14,7 @@ testthat::test_that("constructor accepts a MultiAssayExperiment object", {
})

testthat::test_that("filter_states list is initialized with names of experiments", {
testthat::skip_if_not_installed("MultiAssayExperiment")
testfd <- R6::R6Class(
"testfd",
inherit = MAEFilteredDataset,
Expand All @@ -30,6 +32,7 @@ testthat::test_that("filter_states list is initialized with names of experiments

# format ---
testthat::test_that("format returns properly formatted string", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filtered_dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand Down Expand Up @@ -59,6 +62,7 @@ testthat::test_that("format returns properly formatted string", {

# print ---
testthat::test_that("print returns properly formatted string", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filtered_dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand Down Expand Up @@ -88,13 +92,15 @@ testthat::test_that("print returns properly formatted string", {

# get_call ----
testthat::test_that("get_call returns NULL when no filter applied", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filtered_dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniACC")
get_call_output <- shiny::isolate(filtered_dataset$get_call())
testthat::expect_null(get_call_output)
})

testthat::test_that("get_call returns a call with applying filter", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filtered_dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand Down Expand Up @@ -131,6 +137,7 @@ testthat::test_that("get_call returns a call with applying filter", {

# get_filter_overview ----
testthat::test_that("get_filter_overview_info returns overview matrix for MAEFilteredDataset without filtering", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filtered_dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniACC")
testthat::expect_equal(
Expand All @@ -146,6 +153,7 @@ testthat::test_that("get_filter_overview_info returns overview matrix for MAEFil
})

testthat::test_that("get_filter_overview_info returns overview matrix for MAEFilteredDataset with filtering", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filtered_dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand Down Expand Up @@ -177,6 +185,7 @@ testthat::test_that("get_filter_overview_info returns overview matrix for MAEFil
testthat::test_that(
"MAEFilteredDataset$set_filter_state sets filters in `FilterStates` specified by `teal_slices",
code = {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand Down Expand Up @@ -217,6 +226,7 @@ testthat::test_that(
testthat::test_that(
"MAEFilteredDataset$set_filter_state only acceps `teal_slices",
code = {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- list(
Expand All @@ -236,6 +246,7 @@ testthat::test_that(
testthat::test_that(
"MAEFilteredDataset$get_filter_state returns list identical to input",
code = {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand Down Expand Up @@ -268,6 +279,7 @@ testthat::test_that(
testthat::test_that(
"MAEFilteredDataset$remove_filter_state removes desired filter",
code = {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand Down Expand Up @@ -297,6 +309,7 @@ testthat::test_that(
testthat::test_that(
"MAEFilteredDataset$remove_filter_state only accepts `teal_slices",
code = {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand All @@ -318,6 +331,7 @@ testthat::test_that(

# UI actions ----
testthat::test_that("remove_filters button removes all filters", {
testthat::skip_if_not_installed("MultiAssayExperiment")
utils::data(miniACC, package = "MultiAssayExperiment")
filtered_dataset <- MAEFilteredDataset$new(dataset = miniACC, dataname = "miniacc")
fs <- teal_slices(
Expand Down
Loading

0 comments on commit 3220aac

Please sign in to comment.