diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 501e1b6..f3efee9 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -9,9 +9,9 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - name: Query dependencies run: | diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 3e5b5db..b23c17a 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -19,11 +19,11 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - name: Query dependencies run: | diff --git a/R/app_heatmap.R b/R/app_heatmap.R index 8049dd9..26bfedc 100644 --- a/R/app_heatmap.R +++ b/R/app_heatmap.R @@ -438,10 +438,10 @@ plot_heatmap <- function( heatmap_plot <- ggplot( augmented_tidy_omic_data, - aes_string( - x = "ordered_sampleId", - y = "ordered_featureId", - fill = value_var + aes( + x = !!rlang::sym("ordered_sampleId"), + y = !!rlang::sym("ordered_featureId"), + fill = !!rlang::sym(value_var) ) ) + geom_raster() + diff --git a/R/data_classes.R b/R/data_classes.R index d47c5c7..75636ea 100644 --- a/R/data_classes.R +++ b/R/data_classes.R @@ -706,6 +706,7 @@ tidy_to_triple <- function(tidy_omic) { #' @inheritParams create_tidy_omic #' @param sample_var variable name to use for samples #' @param measurement_var variable name to use for measurements +#' @inheritParams create_tidy_omic #' #' @returns A \code{tidy_omic} object as produced by \code{create_tidy_omic}. #' @@ -724,12 +725,16 @@ tidy_to_triple <- function(tidy_omic) { #' feature_vars = c("BP", "MF", "systematic_name") #' ) #' @export -convert_wide_to_tidy_omic <- function(wide_df, - feature_pk, - feature_vars = NULL, - sample_var = "sample", - measurement_var = "abundance", - omic_type_tag = "general") { +convert_wide_to_tidy_omic <- function( + wide_df, + feature_pk, + feature_vars = NULL, + sample_var = "sample", + measurement_var = "abundance", + omic_type_tag = "general", + verbose = TRUE + ) { + checkmate::assertDataFrame(wide_df) checkmate::assertChoice(feature_pk, colnames(wide_df)) stopifnot(class(feature_vars) %in% c("character", "NULL")) @@ -740,6 +745,7 @@ convert_wide_to_tidy_omic <- function(wide_df, checkmate::assertString(sample_var) checkmate::assertString(measurement_var) checkmate::assertString(omic_type_tag) + checkmate::assertLogical(verbose, len = 1) # test other provided variables reserved_variable_names <- c( @@ -835,7 +841,8 @@ convert_wide_to_tidy_omic <- function(wide_df, feature_pk = feature_pk, feature_vars = feature_vars, sample_pk = sample_var, - omic_type_tag = omic_type_tag + omic_type_tag = omic_type_tag, + verbose = verbose ) return(tidy_omic) diff --git a/R/dim_reduction.R b/R/dim_reduction.R index 760a1d9..36a1a6b 100644 --- a/R/dim_reduction.R +++ b/R/dim_reduction.R @@ -11,6 +11,7 @@ #' @inheritParams remove_missing_values #' @param label_percent_varex If true then PCs will be labelled by the percent #' of variability they explain. +#' @inheritParams create_tidy_omic #' #' @returns A \code{tomic} object with principal components added to samples. #' @@ -24,13 +25,15 @@ add_pcs <- function( center_rows = TRUE, npcs = NULL, missing_val_method = "drop_samples", - label_percent_varex = TRUE + label_percent_varex = TRUE, + verbose = TRUE ) { checkmate::assertClass(tomic, "tomic") checkmate::assertLogical(center_rows, len = 1) stopifnot(length(npcs) <= 1, class(npcs) %in% c("NULL", "numeric", "integer")) checkmate::assertLogical(label_percent_varex, len = 1) + checkmate::assertLogical(verbose, len = 1) design <- tomic$design feature_pk <- design$feature_pk @@ -41,7 +44,8 @@ add_pcs <- function( triple_omic <- tomic_to(tomic, "triple_omic") %>% remove_missing_values( value_var = value_var, - missing_val_method = missing_val_method + missing_val_method = missing_val_method, + verbose = verbose ) cast_formula <- stats::as.formula(paste0(feature_pk, " ~ ", sample_pk)) @@ -129,6 +133,7 @@ add_pcs <- function( #' then drop features} #' \item{impute}{Impute missing values} #' } +#' @inheritParams create_tidy_omic #' #' @returns A \code{tomic} object where missing values have been accounted #' for. @@ -140,12 +145,15 @@ add_pcs <- function( remove_missing_values <- function( tomic, value_var = NULL, - missing_val_method = "drop_samples") { + missing_val_method = "drop_samples", + verbose = TRUE + ) { checkmate::assertClass(tomic, "tomic") checkmate::assertChoice( missing_val_method, c("drop_features", "drop_samples") ) + checkmate::assertLogical(verbose, len = 1) triple_omic <- tomic_to(tomic, "triple_omic") @@ -183,7 +191,10 @@ remove_missing_values <- function( stop(missing_val_method, " is not an implemented missing value method") } } else { - message("No missing values found; returning input tomic") + if (verbose) { + message("No missing values found; returning input tomic") + } + return(tomic) } @@ -198,9 +209,11 @@ remove_missing_values <- function( n_dropped_samples <- n_initial_samples - nrow(triple_omic$samples) if (n_dropped_samples != 0) { - print( - glue::glue("{n_dropped_samples} samples dropped due to missing values") - ) + if (verbose) { + print( + glue::glue("{n_dropped_samples} samples dropped due to missing values") + ) + } } n_dropped_features <- observed_measurements %>% @@ -209,9 +222,11 @@ remove_missing_values <- function( nrow() if (n_dropped_features != 0) { - print( - glue::glue("{n_dropped_features} features dropped due to missing values") - ) + if (verbose) { + print( + glue::glue("{n_dropped_features} features dropped due to missing values") + ) + } } return(tomic_to(triple_omic, class(tomic)[1])) diff --git a/R/export.R b/R/export.R index 2a3ddcf..056f13a 100644 --- a/R/export.R +++ b/R/export.R @@ -5,6 +5,7 @@ #' @inheritParams tomic_to #' @param dir_path path to save outputs #' @param name_preamble start of output file name +#' @inheritParams create_tidy_omic #' #' @returns Export three tables: #' \itemize{ @@ -19,16 +20,24 @@ #' export_tomic_as_triple(brauer_2008_triple, "/tmp", "brauer") #' } #' @export -export_tomic_as_triple <- function(tomic, dir_path, name_preamble) { +export_tomic_as_triple <- function( + tomic, + dir_path, + name_preamble, + verbose = TRUE + ) { checkmate::assertDirectory(dir_path) checkmate::assertString(name_preamble) + checkmate::assertLogical(verbose, len = 1) triple_omic <- tomic_to(tomic, "triple_omic") - message(glue::glue( - "Saving {name_preamble}_features.tsv, {name_preamble}_samples.tsv, and + if (verbose) { + message(glue::glue( + "Saving {name_preamble}_features.tsv, {name_preamble}_samples.tsv, and {name_preamble}_measurements.tsv to {dir_path}" - )) + )) + } for (k in c("features", "samples", "measurements")) { readr::write_tsv( @@ -46,6 +55,7 @@ export_tomic_as_triple <- function(tomic, dir_path, name_preamble) { #' measurements. #' #' @inheritParams export_tomic_as_triple +#' @inheritParams create_tidy_omic #' #' @returns Export one table which is one row per peak, which includes #' all feature and sample attributes. @@ -56,14 +66,17 @@ export_tomic_as_triple <- function(tomic, dir_path, name_preamble) { #' export_tomic_as_tidy(brauer_2008_triple, "/tmp", "brauer") #' } #' @export -export_tomic_as_tidy <- function(tomic, dir_path, name_preamble) { +export_tomic_as_tidy <- function(tomic, dir_path, name_preamble, verbose = TRUE) { checkmate::assertDirectory(dir_path) checkmate::assertString(name_preamble) + checkmate::assertLogical(verbose, len = 1) tidy_omic <- tomic_to(tomic, "tidy_omic") filename <- paste0(name_preamble, "_tidy.tsv") - message(glue::glue("Saving {filename} to {dir_path}")) + if (verbose) { + message(glue::glue("Saving {filename} to {dir_path}")) + } readr::write_tsv( tidy_omic$data, @@ -81,6 +94,7 @@ export_tomic_as_tidy <- function(tomic, dir_path, name_preamble) { #' @inheritParams export_tomic_as_triple #' @param value_var measurement variable to use for the matrix #' @param transpose if TRUE then samples will be stored as rows +#' @inheritParams create_tidy_omic #' #' @returns Export one table which contains metabolites as rows and samples #' as columns. @@ -96,10 +110,13 @@ export_tomic_as_wide <- function( dir_path, name_preamble, value_var = NULL, - transpose = FALSE) { + transpose = FALSE, + verbose = TRUE + ) { checkmate::assertDirectory(dir_path) checkmate::assertString(name_preamble) checkmate::assertLogical(transpose, len = 1) + checkmate::assertLogical(verbose, len = 1) triple_omic <- tomic_to(tomic, "triple_omic") design <- triple_omic$design @@ -245,7 +262,9 @@ export_tomic_as_wide <- function( } filename <- paste0(name_preamble, "_", "wide.tsv") - message(glue::glue("Saving {filename} to {dir_path}")) + if (verbose) { + message(glue::glue("Saving {filename} to {dir_path}")) + } output %>% as.data.frame() %>% diff --git a/R/hclust.R b/R/hclust.R index b43d9e9..c7e1956 100644 --- a/R/hclust.R +++ b/R/hclust.R @@ -322,6 +322,7 @@ apply_hclust <- function(quant_matrix, distance_measure, hclust_method) { #' @param design a list summarizing the design of the tidy dataset #' @param max_display_features aggregate and downsample distinct feature to #' this number to speed to up heatmap rendering. +#' @inheritParams create_tidy_omic #' #' @returns tidy_data with rows collapsed if the number of distinct features is #' greater than \code{max_display_features} @@ -330,10 +331,13 @@ downsample_heatmap <- function( tidy_data, value_var, design, - max_display_features = 1000) { + max_display_features = 1000, + verbose = TRUE + ) { checkmate::assertDataFrame(tidy_data) checkmate::assertChoice(value_var, colnames(tidy_data)) checkmate::assertNumber(max_display_features) + checkmate::assertLogical(verbose, len = 1) if (!("ordered_featureId" %in% colnames(tidy_data))) { stop("ordered_featureId is a requred variable in tidy_data") @@ -358,9 +362,11 @@ downsample_heatmap <- function( realized_max_display_features <- ceiling( n_features / ceiling(n_features / max_display_features) ) - message(glue::glue( - "Downsampling {n_features} features to {realized_max_display_features}, targeting {max_display_features}" - )) + if (verbose) { + message(glue::glue( + "Downsampling {n_features} features to {realized_max_display_features}, targeting {max_display_features}" + )) + } collapsed_rows_merges <- tibble::tibble(ordered_featureId_int = 1:n_features) %>% dplyr::mutate(collapsed_row_number = rep( diff --git a/R/romic.R b/R/romic.R deleted file mode 100644 index e69de29..0000000 diff --git a/man/add_pcs.Rd b/man/add_pcs.Rd index ee93529..288e83f 100644 --- a/man/add_pcs.Rd +++ b/man/add_pcs.Rd @@ -10,7 +10,8 @@ add_pcs( center_rows = TRUE, npcs = NULL, missing_val_method = "drop_samples", - label_percent_varex = TRUE + label_percent_varex = TRUE, + verbose = TRUE ) } \arguments{ @@ -33,6 +34,8 @@ add_pcs( \item{label_percent_varex}{If true then PCs will be labelled by the percent of variability they explain.} + +\item{verbose}{extra reporting messages} } \value{ A \code{tomic} object with principal components added to samples. diff --git a/man/convert_wide_to_tidy_omic.Rd b/man/convert_wide_to_tidy_omic.Rd index edc09a4..9562210 100644 --- a/man/convert_wide_to_tidy_omic.Rd +++ b/man/convert_wide_to_tidy_omic.Rd @@ -10,7 +10,8 @@ convert_wide_to_tidy_omic( feature_vars = NULL, sample_var = "sample", measurement_var = "abundance", - omic_type_tag = "general" + omic_type_tag = "general", + verbose = TRUE ) } \arguments{ @@ -28,6 +29,8 @@ variables (or NULL if there are no additional variables)} \item{omic_type_tag}{an optional subtype of omic data: metabolomics, lipidomics, proteomics, genomics, general} + +\item{verbose}{extra reporting messages} } \value{ A \code{tidy_omic} object as produced by \code{create_tidy_omic}. diff --git a/man/downsample_heatmap.Rd b/man/downsample_heatmap.Rd index 8f4203d..ffd7953 100644 --- a/man/downsample_heatmap.Rd +++ b/man/downsample_heatmap.Rd @@ -4,7 +4,13 @@ \alias{downsample_heatmap} \title{Downsample Heatmap} \usage{ -downsample_heatmap(tidy_data, value_var, design, max_display_features = 1000) +downsample_heatmap( + tidy_data, + value_var, + design, + max_display_features = 1000, + verbose = TRUE +) } \arguments{ \item{tidy_data}{The data frame from a \code{tidy_omic} object containing @@ -17,6 +23,8 @@ and ordered_sampleId.} \item{max_display_features}{aggregate and downsample distinct feature to this number to speed to up heatmap rendering.} + +\item{verbose}{extra reporting messages} } \value{ tidy_data with rows collapsed if the number of distinct features is diff --git a/man/export_tomic_as_tidy.Rd b/man/export_tomic_as_tidy.Rd index 071f744..9acfc2a 100644 --- a/man/export_tomic_as_tidy.Rd +++ b/man/export_tomic_as_tidy.Rd @@ -4,7 +4,7 @@ \alias{export_tomic_as_tidy} \title{Export T*Omic in Tidy Format} \usage{ -export_tomic_as_tidy(tomic, dir_path, name_preamble) +export_tomic_as_tidy(tomic, dir_path, name_preamble, verbose = TRUE) } \arguments{ \item{tomic}{Either a \code{tidy_omic} or \code{triple_omic} object} @@ -12,6 +12,8 @@ export_tomic_as_tidy(tomic, dir_path, name_preamble) \item{dir_path}{path to save outputs} \item{name_preamble}{start of output file name} + +\item{verbose}{extra reporting messages} } \value{ Export one table which is one row per peak, which includes diff --git a/man/export_tomic_as_triple.Rd b/man/export_tomic_as_triple.Rd index bdff2e8..02ac255 100644 --- a/man/export_tomic_as_triple.Rd +++ b/man/export_tomic_as_triple.Rd @@ -4,7 +4,7 @@ \alias{export_tomic_as_triple} \title{Export T*Omic as Triple} \usage{ -export_tomic_as_triple(tomic, dir_path, name_preamble) +export_tomic_as_triple(tomic, dir_path, name_preamble, verbose = TRUE) } \arguments{ \item{tomic}{Either a \code{tidy_omic} or \code{triple_omic} object} @@ -12,6 +12,8 @@ export_tomic_as_triple(tomic, dir_path, name_preamble) \item{dir_path}{path to save outputs} \item{name_preamble}{start of output file name} + +\item{verbose}{extra reporting messages} } \value{ Export three tables: diff --git a/man/export_tomic_as_wide.Rd b/man/export_tomic_as_wide.Rd index 66807bc..4af5e0e 100644 --- a/man/export_tomic_as_wide.Rd +++ b/man/export_tomic_as_wide.Rd @@ -9,7 +9,8 @@ export_tomic_as_wide( dir_path, name_preamble, value_var = NULL, - transpose = FALSE + transpose = FALSE, + verbose = TRUE ) } \arguments{ @@ -22,6 +23,8 @@ export_tomic_as_wide( \item{value_var}{measurement variable to use for the matrix} \item{transpose}{if TRUE then samples will be stored as rows} + +\item{verbose}{extra reporting messages} } \value{ Export one table which contains metabolites as rows and samples diff --git a/man/remove_missing_values.Rd b/man/remove_missing_values.Rd index 3a77d20..20327ad 100644 --- a/man/remove_missing_values.Rd +++ b/man/remove_missing_values.Rd @@ -7,7 +7,8 @@ remove_missing_values( tomic, value_var = NULL, - missing_val_method = "drop_samples" + missing_val_method = "drop_samples", + verbose = TRUE ) } \arguments{ @@ -22,6 +23,8 @@ remove_missing_values( then drop features} \item{impute}{Impute missing values} }} + +\item{verbose}{extra reporting messages} } \value{ A \code{tomic} object where missing values have been accounted diff --git a/tests/testthat.R b/tests/testthat.R index 9dc1a7b..093ee49 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -6,7 +6,7 @@ # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview # * https://testthat.r-lib.org/articles/special-files.html -library(testthat) +suppressPackageStartupMessages(library(testthat)) library(romic) test_check("romic") diff --git a/R/helper.R b/tests/testthat/helper.R similarity index 95% rename from R/helper.R rename to tests/testthat/helper.R index b81d1f1..0fdb0d7 100644 --- a/R/helper.R +++ b/tests/testthat/helper.R @@ -1,5 +1,7 @@ # setup tidy omics +suppressPackageStartupMessages(library(dplyr)) + three_col_df <- tidyr:::expand_grid( features = 1:10, samples = 1:10 diff --git a/tests/testthat/test-app_heatmap.R b/tests/testthat/test-app_heatmap.R new file mode 100644 index 0000000..6ea1375 --- /dev/null +++ b/tests/testthat/test-app_heatmap.R @@ -0,0 +1,44 @@ +test_that("Create heatmap", { + + tomic <- brauer_2008_triple %>% + filter_tomic( + filter_type = "category", + filter_table = "features", + filter_variable = "BP", + filter_value = c( + "protein biosynthesis", + "rRNA processing", "response to stress" + ) + ) + + grob <- plot_heatmap( + tomic = tomic, + value_var = "expression", + change_threshold = 5, + cluster_dim = "rows", + plot_type = "grob", + distance_measure = "corr" + ) + expect_s3_class(grob, "ggplot") + + grob <- plot_heatmap( + tomic = tomic, + value_var = "expression", + change_threshold = 5, + cluster_dim = "both", + plot_type = "grob", + distance_measure = "dist" + ) + expect_s3_class(grob, "ggplot") + + plt <- plot_heatmap( + tomic = tomic, + value_var = "expression", + change_threshold = 5, + cluster_dim = "rows", + plot_type = "plotly", + distance_measure = "corr" + ) + expect_s3_class(plt, "plotly") + +}) diff --git a/tests/testthat/test-data_classes.R b/tests/testthat/test-data_classes.R index ee32132..9f43aea 100644 --- a/tests/testthat/test-data_classes.R +++ b/tests/testthat/test-data_classes.R @@ -27,6 +27,16 @@ test_that("Test check_tidy_omic edge cases", { degen_feature_var = rep(1:10, times = 10) ) + # check verbose message + expect_message( + create_tidy_omic( + three_col_df, + feature_pk = "features", + sample_pk = "samples" + ), + regexp = "1 measurement variables" + ) + expect_snapshot( create_tidy_omic( degenerate_attributes %>% select(-degen_sample_var), @@ -76,7 +86,7 @@ test_that("Factor primary keys are preserved when converting from a tidy to a tr triple_from_tidy_check_status <- romic::check_tomic(triple_from_tidy, fast_check = FALSE) expect_equal(triple_from_tidy_check_status, 0) - tidy_with_pcs <- add_pcs(tidy) + tidy_with_pcs <- add_pcs(tidy, verbose = FALSE) expect_true(sum(stringr::str_detect(colnames(tidy_with_pcs$data), "^PC")) > 1) }) @@ -86,7 +96,7 @@ test_that("Numeric primary keys are preserved when converting from a tidy to a t triple_from_tidy_check_status <- check_tomic(triple_from_tidy, fast_check = FALSE) expect_equal(triple_from_tidy_check_status, 0) - tidy_with_pcs <- add_pcs(simple_tidy) + tidy_with_pcs <- add_pcs(simple_tidy, verbose = FALSE) expect_true(sum(stringr::str_detect(colnames(tidy_with_pcs$data), "^PC")) > 1) }) @@ -101,8 +111,6 @@ test_that("Create triple omic", { sample_pk = "sample_id" ) - - }) @@ -117,7 +125,8 @@ test_that("Read wide data", { tidy_omic <- convert_wide_to_tidy_omic( wide_df, feature_pk = "name", - feature_vars = c("BP", "MF", "systematic_name") + feature_vars = c("BP", "MF", "systematic_name"), + verbose = FALSE ) testthat::expect_s3_class(tidy_omic, "tidy_omic") diff --git a/tests/testthat/test-design.R b/tests/testthat/test-design.R index c699866..a9483c5 100644 --- a/tests/testthat/test-design.R +++ b/tests/testthat/test-design.R @@ -1,4 +1,7 @@ test_that("extract design as a table", { get_design_tbl(brauer_2008_tidy) %>% expect_snapshot() + + expect_invisible(check_design(brauer_2008_tidy)) }) + diff --git a/tests/testthat/test-export.R b/tests/testthat/test-export.R index 8547c69..2b9467c 100644 --- a/tests/testthat/test-export.R +++ b/tests/testthat/test-export.R @@ -1,14 +1,14 @@ test_that("Read and Write Triple Omics", { if (dir.exists("/tmp")) { - export_tomic_as_triple(brauer_2008_triple, "/tmp", "brauer") + export_tomic_as_triple(brauer_2008_triple, "/tmp", "brauer", verbose = FALSE) features_path <- file.path("/tmp", "brauer_features.tsv") measurements_path <- file.path("/tmp", "brauer_measurements.tsv") samples_path <- file.path("/tmp", "brauer_samples.tsv") - features <- readr::read_tsv(features_path) - measurements <- readr::read_tsv(measurements_path) - samples <- readr::read_tsv(samples_path) + features <- readr::read_tsv(features_path, show_col_types = FALSE) + measurements <- readr::read_tsv(measurements_path, show_col_types = FALSE) + samples <- readr::read_tsv(samples_path, show_col_types = FALSE) # cleanup unlink(features_path) @@ -49,10 +49,10 @@ test_that("Read and Write Triple Omics", { test_that("Read and Write Tidy Omics", { if (dir.exists("/tmp")) { - export_tomic_as_tidy(brauer_2008_tidy, "/tmp", "brauer") + export_tomic_as_tidy(brauer_2008_tidy, "/tmp", "brauer", verbose = FALSE) tidy_path <- file.path("/tmp", "brauer_tidy.tsv") - tidy_data <- readr::read_tsv(tidy_path) + tidy_data <- readr::read_tsv(tidy_path, show_col_types = FALSE) # cleanup unlink(tidy_path) @@ -63,7 +63,8 @@ test_that("Read and Write Tidy Omics", { feature_pk = "name", feature_vars = c("BP", "MF", "systematic_name"), sample_pk = "sample", - sample_vars = c("nutrient", "DR") + sample_vars = c("nutrient", "DR"), + verbose = FALSE ) tomic_fill_nas <- tomic$data %>% @@ -80,12 +81,17 @@ test_that("Read and Write Tidy Omics", { test_that("Read and Write Wide Data", { if (dir.exists("/tmp")) { - export_tomic_as_wide(brauer_2008_triple, "/tmp", "brauer") + export_tomic_as_wide(brauer_2008_triple, "/tmp", "brauer", verbose = FALSE) wide_path <- file.path("/tmp", "brauer_wide.tsv") # the wide data importer is currently incomplete and doesn't # support sample attributes - wide_data <- suppressWarnings(readr::read_tsv(wide_path)) + wide_data <- suppressMessages(suppressWarnings(readr::read_tsv( + wide_path, + show_col_types = FALSE + ))) + + expect_s3_class(wide_data, "tbl") # cleanup unlink(wide_path) diff --git a/tests/testthat/test-hclust.R b/tests/testthat/test-hclust.R index 6568ba3..fe13a32 100644 --- a/tests/testthat/test-hclust.R +++ b/tests/testthat/test-hclust.R @@ -85,7 +85,8 @@ test_that("downsampling features (for creating a heatmap works)", { downsample_heatmap( value_var = "expression", design = brauer_2008_tidy$design, - max_display_features = 100 + max_display_features = 100, + verbose = FALSE ) expect_equal(nrow(downsampled_df), 3600) diff --git a/tests/testthat/test-module_ggbiv.R b/tests/testthat/test-module_ggbiv.R new file mode 100644 index 0000000..f8a1a00 --- /dev/null +++ b/tests/testthat/test-module_ggbiv.R @@ -0,0 +1,38 @@ +test_that("multiplication works", { + + brauer_augmented <- brauer_2008_tidy %>% + add_pcs(npcs = 5, verbose = FALSE) %>% + tomic_to("triple_omic") + + tomic_table <- brauer_augmented$samples + grob <- plot_bivariate(tomic_table, "PC1", "PC2", "nutrient", "nutrient", 0.5, 10) + expect_s3_class(grob, "ggplot") + + grob <- plot_bivariate(tomic_table, "nutrient", "PC2", "nutrient") + expect_s3_class(grob, "ggplot") + + }) + +test_that("List viable variables for a plot", { + + expect_equal( + get_design_vars(brauer_2008_tidy, plot_table = "measurements", "categorical"), + c("name", "sample") + ) + + expect_equal( + get_design_vars(brauer_2008_tidy, plot_table = "features", "all"), + c("name", "systematic_name", "BP", "MF") + ) + + expect_equal( + get_design_vars(brauer_2008_tidy, plot_table = "samples", "quantitative"), + "DR" + ) + + expect_equal( + get_design_vars(brauer_2008_tidy, plot_table = "samples", "all"), + brauer_2008_tidy$design$samples$variable + ) + +}) diff --git a/tests/testthat/test-module_gguniv.R b/tests/testthat/test-module_gguniv.R new file mode 100644 index 0000000..6626c3a --- /dev/null +++ b/tests/testthat/test-module_gguniv.R @@ -0,0 +1,8 @@ +test_that("Univariate plotting works", { + grob <- plot_univariate( + get_tomic_table(simple_tidy, "measurements"), + "features" + ) + + expect_s3_class(grob, "ggplot") +})