diff --git a/NAMESPACE b/NAMESPACE index f96e879..1dfc924 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,8 @@ S3method(ctl_new_rowid_pillar,SE_print_abstraction) S3method(print,SummarizedExperiment) S3method(tbl_format_header,SE_print_abstraction) S3method(tbl_format_header,tidySummarizedExperiment) +export(test_tidy_message) +export(tidy_message) importClassesFrom(SummarizedExperiment,SummarizedExperiment) importFrom(S4Vectors,coolcat) importFrom(S4Vectors,metadata) diff --git a/R/tidyprint_message.R b/R/tidyprint_message.R new file mode 100644 index 0000000..17a2bdd --- /dev/null +++ b/R/tidyprint_message.R @@ -0,0 +1,45 @@ +#' Print styled tidyprint messages +#' +#' @param message A character string containing the message to display. +#' @param type The type of message to display ("info", "success", "warning", "danger"). Defaults to "info". +#' @export +#' @examples +#' tidy_message("Loading data...", type = "info") +#' tidy_message("Data loaded successfully!", type = "success") +tidy_message <- function(message, type = c("info", "success", "warning", "danger")) { + type <- match.arg(type, choices = c("info", "success", "warning", "danger")) + + calling_package <- utils::packageName(parent.frame()) + prefix_package <- ifelse(is.null(calling_package), "Console", calling_package) + + # prefix <- switch( + # type, + # info = paste0(prefix_package, " says"), + # success = paste0(prefix_package, " success"), + # warning = paste0(prefix_package, " warning"), + # danger = paste0(prefix_package, " error") + # ) + + prefix = paste0(prefix_package, " says") + + style_fun <- switch( + type, + info = cli::cli_alert_info, + success = cli::cli_alert_success, + warning = cli::cli_alert_warning, + danger = cli::cli_alert_danger + ) + + style_fun("{prefix}: {message}") +} + +#' Test tidy_message function +#' @export +#' @examples +#' test_tidy_message() +test_tidy_message <- function() { + tidy_message("This is an informational message send within tidyprint package.") + tidy_message("Operation completed successfully!", type = "success") + tidy_message("Potential issue detected.", type = "warning") + tidy_message("Operation failed.", type = "danger") +} diff --git a/README.md b/README.md index 73b5da8..874cd25 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,13 @@ tidyprint -**tidyprint** is an R package that provides multiple printing styles for -`SummarizedExperiment` objects. You can choose among: +**tidyprint** is an R package that provides a centralised tidy display +strategy for biological data (e.g. SummarizedExperiment), and +centralised messaging styles for the `tidyomics` packages. To facilitate +the discussion about data display, we compare here four data diplay: -1. **SummarizedExperiment** (default): Standard R/SummarizedExperiment - printing style. +1. **SummarizedExperiment**: Standard R/SummarizedExperiment printing + style. 2. **tidyprint_1**: Newly designed tibble abstraction, combines styles from **tidySummarizedExperiment** and **plyxp** @@ -27,17 +29,17 @@ it easy to switch between these printing styles. ## 1. Installation -You need the \`\` package to install from GitHub. If you don’t have it, -install via: +You need the `remotes` package to install from GitHub. If you don’t have +it, install via: ``` r -install.packages("devtools") +install.packages("remotes") ``` Then install **tidyprint** from GitHub: ``` r -devtools::install_github("tidyomics/tidyprint") +remotes::install_github("tidyomics/tidyprint") ``` ------------------------------------------------------------------------ @@ -126,24 +128,6 @@ se_airway %>% print(design = "tidyprint_1") #> 309552 ENSG00000283123 SRR1039521 | 0 | | treated N061011 GSM1275875 ``` -You can also limit the number of displayed rows by setting `n_print` (or -a similar argument in your code): - -``` r - -se_airway %>% print(design = "tidyprint_1", n_print = 5) -#> # A SummarizedExperiment-tibble abstraction: -#> # Features=38694 | Samples=8 | Assays=counts -#> .features .samples `|` counts `|` `|` dex celltype geo_id -#> <|> <|> <|> -#> 1 ENSG00000000003 SRR1039508 | 723 | | control N61311 GSM1275862 -#> 2 ENSG00000000005 SRR1039508 | 0 | | control N61311 GSM1275862 -#> 3 ENSG00000000419 SRR1039508 | 467 | | control N61311 GSM1275862 -#> --------------- ---------- -- --- -- -- ------- ------- ---------- -#> 309551 ENSG00000283120 SRR1039521 | 0 | | treated N061011 GSM1275875 -#> 309552 ENSG00000283123 SRR1039521 | 0 | | treated N061011 GSM1275875 -``` - ### 2.4 **tidySummarizedExperiment** Use the “tidySummarizedExperiment” design to view your data in a @@ -194,20 +178,21 @@ se_airway %>% print(design = "plyxp") #> 10 ENSG00000283123 SRR1039521 | 0 | | treated N061011 GSM1275875 ``` -You can also limit the number of displayed rows by setting `n_print` (or -a similar argument in your code): +# Messaging function + +We integrated a messaging function providing standardized, visually +appealing messages for packages within the tidyomics ecosystem. It +automatically detects the calling package to provide contextualized +messaging, such as “tidyprint says” or “tidybulk says”, enhancing +consistency and readability across projects. ``` r -se_airway %>% print(design = "plyxp", n_print = 5) -#> # A tibble: 5 × 9 -#> .features .samples `|` counts `|` `|` dex celltype geo_id -#> <|> <|> <|> -#> 1 ENSG00000000003 SRR1039508 | 723 | | control N61311 GSM1275862 -#> 2 ENSG00000000005 SRR1039508 | 0 | | control N61311 GSM1275862 -#> 3 ENSG00000000419 SRR1039508 | 467 | | control N61311 GSM1275862 -#> 4 ENSG00000283120 SRR1039521 | 0 | | treated N061011 GSM1275875 -#> 5 ENSG00000283123 SRR1039521 | 0 | | treated N061011 GSM1275875 +test_tidy_message() +#> ℹ tidyprint says: This is an informational message send within tidyprint package. +#> ✔ tidyprint says: Operation completed successfully! +#> ! tidyprint says: Potential issue detected. +#> ✖ tidyprint says: Operation failed. ``` ## Session info diff --git a/man/test_tidy_message.Rd b/man/test_tidy_message.Rd new file mode 100644 index 0000000..7244deb --- /dev/null +++ b/man/test_tidy_message.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tidyprint_message.R +\name{test_tidy_message} +\alias{test_tidy_message} +\title{Test tidy_message function} +\usage{ +test_tidy_message() +} +\description{ +Test tidy_message function +} +\examples{ +test_tidy_message() +} diff --git a/man/tidy_message.Rd b/man/tidy_message.Rd new file mode 100644 index 0000000..de49993 --- /dev/null +++ b/man/tidy_message.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tidyprint_message.R +\name{tidy_message} +\alias{tidy_message} +\title{Print styled tidyprint messages} +\usage{ +tidy_message(message, type = c("info", "success", "warning", "danger")) +} +\arguments{ +\item{message}{A character string containing the message to display.} + +\item{type}{The type of message to display ("info", "success", "warning", "danger"). Defaults to "info".} +} +\description{ +Print styled tidyprint messages +} +\examples{ +tidy_message("Loading data...", type = "info") +tidy_message("Data loaded successfully!", type = "success") +} diff --git a/tests/testthat/test-print_methods.R b/tests/testthat/test-print_methods.R index 39ed3cc..acd1f71 100644 --- a/tests/testthat/test-print_methods.R +++ b/tests/testthat/test-print_methods.R @@ -55,3 +55,8 @@ test_that("tidyprint_1 print works", { test_that("Invalid design throws an error", { expect_error(print(se_airway, design = "invalidDesign"), "should be one of") }) + +# test for message +test_that("tidy_message works correctly", { + expect_message(tidy_message("Test info message"), "says: Test info message") +}) diff --git a/vignettes/Introduction.Rmd b/vignettes/Introduction.Rmd index 228508f..9c4decf 100644 --- a/vignettes/Introduction.Rmd +++ b/vignettes/Introduction.Rmd @@ -57,9 +57,9 @@ find_figure <- function(names){ -**tidyprint** is an R package that provides multiple printing styles for `SummarizedExperiment` objects. You can choose among: +**tidyprint** is an R package that provides a centralised tidy display strategy for biological data (e.g. SummarizedExperiment), and centralised messaging styles for the `tidyomics` packages. To facilitate the discussion about data display, we compare here four data diplay: -1. **SummarizedExperiment** (default): Standard R/SummarizedExperiment printing style. +1. **SummarizedExperiment**: Standard R/SummarizedExperiment printing style. 2. **tidyprint_1**: Newly designed tibble abstraction, combines styles from **tidySummarizedExperiment** and **plyxp** @@ -73,16 +73,16 @@ Depending on your workflow and desired console output, `tidyprint` makes it easy ## 1. Installation -You need the \`\` package to install from GitHub. If you don’t have it, install via: +You need the `remotes` package to install from GitHub. If you don’t have it, install via: ```{r eval=FALSE} -install.packages("devtools") +install.packages("remotes") ``` Then install **tidyprint** from GitHub: ```{r eval=FALSE} -devtools::install_github("tidyomics/tidyprint") +remotes::install_github("tidyomics/tidyprint") ``` ------------------------------------------------------------------------ @@ -137,15 +137,6 @@ se_airway %>% print(design = "tidyprint_1") ``` -You can also limit the number of displayed rows by setting `n_print` (or a similar argument in your code): - -```{r} - -se_airway %>% print(design = "tidyprint_1", n_print = 5) - -``` - - ### 2.4 **tidySummarizedExperiment** @@ -169,14 +160,17 @@ se_airway %>% print(design = "plyxp") ``` -You can also limit the number of displayed rows by setting `n_print` (or a similar argument in your code): +# Messaging function + +We integrated a messaging function providing standardized, visually appealing messages for packages within the tidyomics ecosystem. It automatically detects the calling package to provide contextualized messaging, such as "tidyprint says" or "tidybulk says", enhancing consistency and readability across projects. ```{r} -se_airway %>% print(design = "plyxp", n_print = 5) +test_tidy_message() ``` + ## Session info ```{r} diff --git a/vignettes/Introduction.html b/vignettes/Introduction.html index 0936d82..898ad7d 100644 --- a/vignettes/Introduction.html +++ b/vignettes/Introduction.html @@ -362,11 +362,13 @@

tidyprint

Lifecycle:experimental

-

tidyprint is an R package that provides multiple -printing styles for SummarizedExperiment objects. You can -choose among:

+

tidyprint is an R package that provides a +centralised tidy display strategy for biological data +(e.g. SummarizedExperiment), and centralised messaging styles for the +tidyomics packages. To facilitate the discussion about data +display, we compare here four data diplay:

    -
  1. SummarizedExperiment (default): Standard +

  2. SummarizedExperiment: Standard R/SummarizedExperiment printing style.

  3. tidyprint_1: Newly designed tibble abstraction, combines styles from tidySummarizedExperiment and @@ -382,11 +384,11 @@

    tidyprint


    1. Installation

    -

    You need the `` package to install from GitHub. If you don’t have it, -install via:

    -
    install.packages("devtools")
    +

    You need the remotes package to install from GitHub. If +you don’t have it, install via:

    +
    install.packages("remotes")

    Then install tidyprint from GitHub:

    -
    devtools::install_github("tidyomics/tidyprint")
    +
    remotes::install_github("tidyomics/tidyprint")

    @@ -461,20 +463,6 @@

    2.3 tidyprint_1

    #> 309550 ENSG00000283119 SRR1039521 | 0 | | treated N061011 GSM1275875 #> 309551 ENSG00000283120 SRR1039521 | 0 | | treated N061011 GSM1275875 #> 309552 ENSG00000283123 SRR1039521 | 0 | | treated N061011 GSM1275875 -

    You can also limit the number of displayed rows by setting -n_print (or a similar argument in your code):

    -
    
    -se_airway %>% print(design = "tidyprint_1", n_print = 5)
    -#> # A SummarizedExperiment-tibble abstraction:
    -#> # Features=38694 | Samples=8 | Assays=counts
    -#>        .features       .samples   `|` counts `|` `|` dex     celltype geo_id    
    -#>        <chr>           <chr>      <|> <chr>  <|> <|> <chr>   <chr>    <chr>     
    -#> 1      ENSG00000000003 SRR1039508  |  723     |   |  control N61311   GSM1275862
    -#> 2      ENSG00000000005 SRR1039508  |  0       |   |  control N61311   GSM1275862
    -#> 3      ENSG00000000419 SRR1039508  |  467     |   |  control N61311   GSM1275862
    -#>        --------------- ---------- --  ---    --  --  ------- -------  ----------
    -#> 309551 ENSG00000283120 SRR1039521  |  0       |   |  treated N061011  GSM1275875
    -#> 309552 ENSG00000283123 SRR1039521  |  0       |   |  treated N061011  GSM1275875

    2.4 tidySummarizedExperiment

    @@ -519,20 +507,21 @@

    2.5 plyxp

    #> 8 ENSG00000283119 SRR1039521 | 0 | | treated N061011 GSM1275875 #> 9 ENSG00000283120 SRR1039521 | 0 | | treated N061011 GSM1275875 #> 10 ENSG00000283123 SRR1039521 | 0 | | treated N061011 GSM1275875 -

    You can also limit the number of displayed rows by setting -n_print (or a similar argument in your code):

    -
    
    -se_airway %>% print(design = "plyxp", n_print = 5)
    -#> # A tibble: 5 × 9
    -#>   .features       .samples   `|` counts `|` `|` dex     celltype geo_id    
    -#>   <chr>           <chr>      <|>  <dbl> <|> <|> <chr>   <chr>    <chr>     
    -#> 1 ENSG00000000003 SRR1039508  |     723  |   |  control N61311   GSM1275862
    -#> 2 ENSG00000000005 SRR1039508  |       0  |   |  control N61311   GSM1275862
    -#> 3 ENSG00000000419 SRR1039508  |     467  |   |  control N61311   GSM1275862
    -#> 4 ENSG00000283120 SRR1039521  |       0  |   |  treated N061011  GSM1275875
    -#> 5 ENSG00000283123 SRR1039521  |       0  |   |  treated N061011  GSM1275875
    +
    +

    Messaging function

    +

    We integrated a messaging function providing standardized, visually +appealing messages for packages within the tidyomics ecosystem. It +automatically detects the calling package to provide contextualized +messaging, such as “tidyprint says” or “tidybulk says”, enhancing +consistency and readability across projects.

    +
    
    +test_tidy_message()
    +#> ℹ tidyprint says: This is an informational message send within tidyprint package.
    +#> ✔ tidyprint says: Operation completed successfully!
    +#> ! tidyprint says: Potential issue detected.
    +#> ✖ tidyprint says: Operation failed.

    Session info

    
    @@ -592,6 +581,7 @@ 

    Session info

    #> [55] knitr_1.49 htmltools_0.5.8.1 #> [57] rmarkdown_2.29 compiler_4.4.0
    +