diff --git a/R/visualization.R b/R/visualization.R index 0a0c984..f51d156 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -947,7 +947,7 @@ plotSlingshot <- function(object, lineage, pt, curves) { #' @param height The height of the plot #' @param dir_output directory to save the output plot (default: ".") #' -#' @return A ggplot object. +#' @return Create and save PCA plot of Seurat cluster abundances. #' #' @examples #' library(Seurat) @@ -1080,4 +1080,5 @@ pcaSeurat <- function(object, cluster, sample, condition, width = 20, height = 5 width = width, height = height, plot = pca_plots ) + return(pca_plots) } diff --git a/man/pcaSeurat.Rd b/man/pcaSeurat.Rd index 22d5a26..afc9d2f 100644 --- a/man/pcaSeurat.Rd +++ b/man/pcaSeurat.Rd @@ -30,7 +30,7 @@ pcaSeurat( \item{dir_output}{directory to save the output plot (default: ".")} } \value{ -A ggplot object. +Create and save PCA plot of Seurat cluster abundances. } \description{ The function creates a PCA plot of the cluster abundances and saves the plot in results/abundance folder @@ -63,4 +63,5 @@ pcaSeurat( width = 20, height = 5 ) +unlink("pbmc_small_condition_cluster.pdf") } diff --git a/tests/testthat/test_visualization.R b/tests/testthat/test_visualization.R index 8d69927..65ebbef 100644 --- a/tests/testthat/test_visualization.R +++ b/tests/testthat/test_visualization.R @@ -488,7 +488,7 @@ test_that("pcaSeurat works as expected", { tibble::column_to_rownames("barcode") # Run the function - pcaSeurat( + plot <- pcaSeurat( object = pbmc_small, cluster = "cluster", sample = "sample", @@ -503,8 +503,15 @@ test_that("pcaSeurat works as expected", { # Test 2: Function creates a file that is not empty expect_gt(file.info("pbmc_small_condition_cluster.pdf")$size, 0) + + # Test 3: Check if the function returns a ggplot object + expect_s3_class(plot, "ggplot") + + # Test 4: Check if the plot is not empty + p <- ggplot2::ggplot_build(plot) + expect_gt(length(p$data), 0) - # Test 3: Check if the function throws an error if object is not a Seurat object + # Test 5: Check if the function throws an error if object is not a Seurat object expect_error( pcaSeurat( object = data.frame(a = 1:3),