From b0e4e7530f57f5c1e4b09eb6b7489f56d62d2c0f Mon Sep 17 00:00:00 2001 From: scheidec Date: Thu, 19 Sep 2024 17:14:39 -0400 Subject: [PATCH] Fix crayon bug and ui_bullet issue - removed crayon and usethis as dependencies in favor of cli - fixed bug in R version 4.4.1 with ui_bullet internal calls within loadAdatsAsList() and write_adat() - Fixes #129 --- DESCRIPTION | 7 +- R/diffAdats.R | 2 +- R/is-intact-attr.R | 10 +- R/loadAdatsAsList.R | 8 +- R/parseCheck.R | 12 +-- R/prepHeaderMeta.R | 2 +- R/utils.R | 24 ++--- R/write-adat.R | 6 +- README.Rmd | 4 +- README.md | 4 +- tests/testthat/_snaps/diffAdats.md | 126 +++++++++++------------ tests/testthat/_snaps/groupGenerics.md | 16 +-- tests/testthat/_snaps/is-intact-attr.md | 4 +- tests/testthat/_snaps/loadAdatsAsList.md | 6 +- 14 files changed, 113 insertions(+), 118 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f7f7cc8..a7b33da 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,15 +24,13 @@ Depends: R (>= 4.1.0) Imports: cli, - crayon, dplyr (>= 1.0.6), lifecycle (>= 1.0.0), magrittr (>= 2.0.1), methods, readxl (>= 1.3.1), tibble (>= 3.1.2), - tidyr (>= 1.1.3), - usethis (>= 2.0.1) + tidyr (>= 1.1.3) Suggests: Biobase, ggplot2, @@ -42,6 +40,7 @@ Suggests: rmarkdown, spelling, testthat (>= 3.0.0), + usethis (>= 2.0.1), withr VignetteBuilder: knitr @@ -54,4 +53,4 @@ LazyLoad: true Config/testthat/edition: 3 Config/Needs/website: tidyverse/tidytemplate Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/R/diffAdats.R b/R/diffAdats.R index c282316..52e5254 100644 --- a/R/diffAdats.R +++ b/R/diffAdats.R @@ -144,7 +144,7 @@ diffAdats <- function(adat1, adat2, tolerance = 1e-06) { } cat("\n") .done( - "Continuing on the {.value('*INTERSECT*')} of ADAT columns" + "Continuing on the {.val *INTERSECT*} of ADAT columns" ) } diff --git a/R/is-intact-attr.R b/R/is-intact-attr.R index bdcdec3..40f1a8e 100644 --- a/R/is-intact-attr.R +++ b/R/is-intact-attr.R @@ -42,14 +42,14 @@ is_intact_attr <- function(adat, verbose = interactive()) { if ( !is.soma_adat(adat) ) { if ( verbose ) { .oops( - "The object is not a `soma_adat` class object: {.value(class(adat))}" + "The object is not a `soma_adat` class object: {.val {class(adat)}}" ) } FALSE } else if ( length(atts) <= 3L ) { if ( verbose ) { .oops( - "Attributes has only 3 entries: {.value(names(atts))}" + "Attributes has only 3 entries: {.val {names(atts)}}" ) } FALSE @@ -61,19 +61,19 @@ is_intact_attr <- function(adat, verbose = interactive()) { } else if ( !all(c("HEADER", "COL_DATA", "ROW_DATA") %in% names(atts$Header.Meta)) ) { if ( verbose ) { diff <- setdiff(c("HEADER", "COL_DATA", "ROW_DATA"), names(atts$Header.Meta)) - .oops(paste("Header.Meta is missing:", .value(diff))) + .oops("Header.Meta is missing: {.val {diff}}") } FALSE } else if ( !all(col_meta_checks %in% names(atts$Col.Meta)) ) { if ( verbose ) { diff <- setdiff(col_meta_checks, names(atts$Col.Meta)) - .oops(paste("Col.Meta is missing:", .value(diff))) + .oops("Col.Meta is missing: {.val {diff}}") } FALSE } else if ( !inherits(atts$Col.Meta, "tbl_df") ) { if ( verbose ) { .oops( - "Col.Meta is not a tibble! -> {.value(class(atts$Col.Meta))}" + "Col.Meta is not a tibble! -> {.val {class(atts$Col.Meta)}}" ) } FALSE diff --git a/R/loadAdatsAsList.R b/R/loadAdatsAsList.R index 574437b..bcf39b4 100644 --- a/R/loadAdatsAsList.R +++ b/R/loadAdatsAsList.R @@ -56,12 +56,12 @@ #' @export loadAdatsAsList <- function(files, collapse = FALSE, verbose = interactive(), ...) { files <- setNames(files, cleanNames(basename(files))) - res <- lapply(files, function(.file) { - x <- tryCatch(read_adat(.file, ...), error = function(e) NULL) + res <- lapply(files, function(file) { + x <- tryCatch(read_adat(file, ...), error = function(e) NULL) if ( is.null(x) ) { - .oops("Failed to load: {.value(.file)}") + .oops("Failed to load: {.val {file}}") } else if ( verbose ) { - .done("Loading: {.value(.file)}") + .done("Loading: {.val {file}}") } x }) diff --git a/R/parseCheck.R b/R/parseCheck.R index a93ae30..20d905b 100644 --- a/R/parseCheck.R +++ b/R/parseCheck.R @@ -159,8 +159,8 @@ parseCheck <- function(all.tokens) { # check col meta match if ( !isTRUE(setequal(col_meta, col_meta2)) ) { .oops("Mismatch between `^COL_DATA` in header and `Col.Meta` block:") - .todo(" In Header: {.value(col_meta)}") - .todo(" In Col.Meta: {.value(col_meta2)}") + .todo(" In Header: {.val {col_meta}}") + .todo(" In Col.Meta: {.val {col_meta2}}") stop("Stopping check early.", call. = FALSE) } @@ -227,8 +227,8 @@ parseCheck <- function(all.tokens) { line_col = "blue", right = cr_red("!") ) ) - .todo("Should be: {.value(table_width)}") - .todo("Currently is: {.value(header_length)}") + .todo("Should be: {.val {table_width}}") + .todo("Currently is: {.val {header_length}}") # print(all.tokens[[ which_header_row ]]) # nolint: commented_code_linter. .oops("Length of the header row is incorrect") .oops("Does not match the width of the data table") @@ -248,7 +248,7 @@ parseCheck <- function(all.tokens) { ) gap_chr <- col_meta2[has_gaps] .todo( - paste("Visually inspect the following Col.Meta rows:", .value(gap_chr)) + paste("Visually inspect the following Col.Meta rows: {.val {gap_chr}}") ) if ( identical(Sys.getenv("TESTTHAT"), "true") || isTRUE(getOption("knitr.in.progress")) ) { @@ -258,7 +258,7 @@ parseCheck <- function(all.tokens) { } cat(.symb, "They may be missing in: ") print(.value(c("Spuriomers", "HybControls"))) - .todo("This is non-critical in ADATs with new {.value('seq.1234.56')} format.") + .todo("This is non-critical in ADATs with new {.val {'seq.1234.56'}} format.") } writeLines(cli_rule("Parse Diagnostic Complete", line = 2, line_col = "green")) } diff --git a/R/prepHeaderMeta.R b/R/prepHeaderMeta.R index 94cccd2..7e529f0 100644 --- a/R/prepHeaderMeta.R +++ b/R/prepHeaderMeta.R @@ -66,7 +66,7 @@ prepHeaderMeta <- function(data) { if ( !("Version" %in% names(x$Header.Meta$HEADER) && x$Header.Meta$HEADER$Version == "1.2") ) { x$Header.Meta$HEADER$Version <- "1.2" - .done("Updating ADAT version to: {.value('1.2')}") + .done("Updating ADAT version to: {.val 1.2}") } if ( "CreatedBy" %in% names(x$Header.Meta$HEADER) ) { diff --git a/R/utils.R b/R/utils.R index a09b3e6..08e6785 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,10 +1,10 @@ -# internal helpers similar to `usethis::ui_*()` functions +# internal helpers similar to `usethis` functions .value <- function(x) { if ( identical(Sys.getenv("TESTTHAT"), "true") ) { paste(encodeString(x, quote = "'"), collapse = ", ") } else { - usethis::ui_value(x) + cli::cli_text("{.val {x}}") } } @@ -17,22 +17,22 @@ paste0("\033[90m", encodeString(x, quote = "`"), "\033[39m") } -# borrow from usethis, cli, and crayon for internal use +# borrow from cli for internal use # without explicitly importing the package in NAMESPACE file # avoid R CMD check NOTE: # "Namespace in Imports field not imported from: 'pkg'" -.todo <- usethis::ui_todo -.done <- usethis::ui_done -.oops <- usethis::ui_oops +.todo <- cli::cli_alert +.done <- cli::cli_alert_success +.oops <- cli::cli_alert_danger # -------------------------- # cli_rule <- cli::rule # -------------------------- # -cr_bold <- crayon::bold -cr_green <- crayon::green -cr_cyan <- crayon::cyan -cr_red <- crayon::red -cr_blue <- crayon::blue -cr_yellow <- crayon::yellow +cr_bold <- cli::style_bold +cr_green <- cli::col_green +cr_cyan <- cli::col_cyan +cr_red <- cli::col_red +cr_blue <- cli::col_blue +cr_yellow <- cli::col_yellow # wrapper around padding; default to right side padding diff --git a/R/write-adat.R b/R/write-adat.R index 92a9349..55e7655 100644 --- a/R/write-adat.R +++ b/R/write-adat.R @@ -47,7 +47,7 @@ write_adat <- function(x, file) { if ( !grepl("\\.adat$", file) ) { warning( - "File extension is not `*.adat` (", .value(file), "). ", + "File extension is not `*.adat` ('", file, "'). ", "Are you sure this is the correct file extension?", call. = FALSE ) @@ -103,7 +103,7 @@ write_adat <- function(x, file) { if ( n_meta < 1L ) { warning( "\nYou are writing an ADAT without any meta data.\n", - "This may cause this file (", .value(file), ") ", + "This may cause this file ('", file, "') ", "to be unreadable via `read_adat()`.\n", "Suggest including at least one column of meta data (e.g. 'sample_id').", call. = FALSE @@ -139,7 +139,7 @@ write_adat <- function(x, file) { fileEncoding = "UTF-8" ) } - .done("ADAT written to: {.value(file)}") + .done("ADAT written to: {.val {file}}") invisible(x) } diff --git a/README.Rmd b/README.Rmd index 1683327..d028b39 100644 --- a/README.Rmd +++ b/README.Rmd @@ -109,14 +109,12 @@ file): * [R (>= 4.1.0)](https://cran.r-project.org/) * [cli](https://cran.r-project.org/package=cli) -* [crayon](https://cran.r-project.org/package=crayon) * [dplyr](https://cran.r-project.org/package=dplyr) * [lifecycle](https://cran.r-project.org/package=lifecycle) * [magrittr](https://cran.r-project.org/package=magrittr) * [readxl](https://cran.r-project.org/package=readxl) * [tibble](https://cran.r-project.org/package=tibble) * [tidyr](https://cran.r-project.org/package=tidyr) -* [usethis](https://cran.r-project.org/package=usethis) #### Biobase @@ -141,7 +139,7 @@ Information about Bioconductor can be found here: #### Loading -Upon _successful_ installation, load the `SomaDataIO` as normal: +Upon _successful_ installation, load `SomaDataIO` as normal: ```{r load-somadataio, eval = FALSE} library(SomaDataIO) diff --git a/README.md b/README.md index 6acb46b..a24ae3d 100644 --- a/README.md +++ b/README.md @@ -87,14 +87,12 @@ file): - [R (\>= 4.1.0)](https://cran.r-project.org/) - [cli](https://cran.r-project.org/package=cli) -- [crayon](https://cran.r-project.org/package=crayon) - [dplyr](https://cran.r-project.org/package=dplyr) - [lifecycle](https://cran.r-project.org/package=lifecycle) - [magrittr](https://cran.r-project.org/package=magrittr) - [readxl](https://cran.r-project.org/package=readxl) - [tibble](https://cran.r-project.org/package=tibble) - [tidyr](https://cran.r-project.org/package=tidyr) -- [usethis](https://cran.r-project.org/package=usethis) #### Biobase @@ -117,7 +115,7 @@ Information about Bioconductor can be found here: #### Loading -Upon *successful* installation, load the `SomaDataIO` as normal: +Upon *successful* installation, load `SomaDataIO` as normal: ``` r library(SomaDataIO) diff --git a/tests/testthat/_snaps/diffAdats.md b/tests/testthat/_snaps/diffAdats.md index 2fccc46..4e8adfc 100644 --- a/tests/testthat/_snaps/diffAdats.md +++ b/tests/testthat/_snaps/diffAdats.md @@ -5,17 +5,17 @@ Output == Checking ADAT attributes & characteristics ================================== Message - * Attribute names are identical v - * Attributes are identical v - * ADAT dimensions are identical v - * ADAT row names are identical v - * ADATs contain identical Features v - * ADATs contain same Meta Fields v + > Attribute names are identical v + > Attributes are identical v + > ADAT dimensions are identical v + > ADAT row names are identical v + > ADATs contain identical Features v + > ADATs contain same Meta Fields v Output -- Checking the data matrix ---------------------------------------------------- Message - * All Clinical data is identical v - * All Feature data is identical v + > All Clinical data is identical v + > All Feature data is identical v Output ================================================================================ @@ -26,27 +26,27 @@ Output == Checking ADAT attributes & characteristics ================================== Message - * Attribute names are identical v - * Attributes are identical x - * ADAT dimensions are identical x - * ADATs have same # of rows v - * ADATs have same # of columns x - * ADATs have same # of features x - * ADATs have same # of meta data v - * ADAT row names are identical v - * ADATs contain identical Features x - * ADATs contain same Meta Fields v + > Attribute names are identical v + > Attributes are identical x + > ADAT dimensions are identical x + > ADATs have same # of rows v + > ADATs have same # of columns x + > ADATs have same # of features x + > ADATs have same # of meta data v + > ADAT row names are identical v + > ADATs contain identical Features x + > ADATs contain same Meta Fields v Output Features in 'adat' but not 'adat[, -9L]': seq.3333.33 Message - v Continuing on the '*INTERSECT*' of ADAT columns + v Continuing on the "*INTERSECT*" of ADAT columns Output -- Checking the data matrix ---------------------------------------------------- Message - * All Clinical data is identical v - * All Feature data is identical v + > All Clinical data is identical v + > All Feature data is identical v Output ================================================================================ @@ -57,27 +57,27 @@ Output == Checking ADAT attributes & characteristics ================================== Message - * Attribute names are identical v - * Attributes are identical x - * ADAT dimensions are identical x - * ADATs have same # of rows v - * ADATs have same # of columns x - * ADATs have same # of features v - * ADATs have same # of meta data x - * ADAT row names are identical v - * ADATs contain identical Features v - * ADATs contain same Meta Fields x + > Attribute names are identical v + > Attributes are identical x + > ADAT dimensions are identical x + > ADATs have same # of rows v + > ADATs have same # of columns x + > ADATs have same # of features v + > ADATs have same # of meta data x + > ADAT row names are identical v + > ADATs contain identical Features v + > ADATs contain same Meta Fields x Output Meta data in 'adat' but not 'adat[, -3L]': Subarray Message - v Continuing on the '*INTERSECT*' of ADAT columns + v Continuing on the "*INTERSECT*" of ADAT columns Output -- Checking the data matrix ---------------------------------------------------- Message - * All Clinical data is identical v - * All Feature data is identical v + > All Clinical data is identical v + > All Feature data is identical v Output ================================================================================ @@ -88,27 +88,27 @@ Output == Checking ADAT attributes & characteristics ================================== Message - * Attribute names are identical v - * Attributes are identical x - * ADAT dimensions are identical x - * ADATs have same # of rows v - * ADATs have same # of columns x - * ADATs have same # of features v - * ADATs have same # of meta data x - * ADAT row names are identical v - * ADATs contain identical Features v - * ADATs contain same Meta Fields x + > Attribute names are identical v + > Attributes are identical x + > ADAT dimensions are identical x + > ADATs have same # of rows v + > ADATs have same # of columns x + > ADATs have same # of features v + > ADATs have same # of meta data x + > ADAT row names are identical v + > ADATs contain identical Features v + > ADATs contain same Meta Fields x Output Meta data in 'new' but not 'adat': foo Message - v Continuing on the '*INTERSECT*' of ADAT columns + v Continuing on the "*INTERSECT*" of ADAT columns Output -- Checking the data matrix ---------------------------------------------------- Message - * All Clinical data is identical v - * All Feature data is identical v + > All Clinical data is identical v + > All Feature data is identical v Output ================================================================================ @@ -119,22 +119,22 @@ Output == Checking ADAT attributes & characteristics ================================== Message - * Attribute names are identical v - * Attributes are identical v - * ADAT dimensions are identical v - * ADAT row names are identical v - * ADATs contain identical Features v - * ADATs contain same Meta Fields v + > Attribute names are identical v + > Attributes are identical v + > ADAT dimensions are identical v + > ADAT row names are identical v + > ADATs contain identical Features v + > ADATs contain same Meta Fields v Output -- Checking the data matrix ---------------------------------------------------- Message - * All Clinical data is identical x + > All Clinical data is identical x Output No. fields that differ 1 -- Clinical data diffs --------------------------------------------------------- [1] "'Subarray'" Message - * All Feature data is identical v + > All Feature data is identical v Output ================================================================================ @@ -145,17 +145,17 @@ Output == Checking ADAT attributes & characteristics ================================== Message - * Attribute names are identical v - * Attributes are identical v - * ADAT dimensions are identical v - * ADAT row names are identical v - * ADATs contain identical Features v - * ADATs contain same Meta Fields v + > Attribute names are identical v + > Attributes are identical v + > ADAT dimensions are identical v + > ADAT row names are identical v + > ADATs contain identical Features v + > ADATs contain same Meta Fields v Output -- Checking the data matrix ---------------------------------------------------- Message - * All Clinical data is identical v - * All Feature data is identical x + > All Clinical data is identical v + > All Feature data is identical x Output No. fields that differ 2 -- Feature data diffs ---------------------------------------------------------- diff --git a/tests/testthat/_snaps/groupGenerics.md b/tests/testthat/_snaps/groupGenerics.md index cecc5ed..025e240 100644 --- a/tests/testthat/_snaps/groupGenerics.md +++ b/tests/testthat/_snaps/groupGenerics.md @@ -5,17 +5,17 @@ Output == Checking ADAT attributes & characteristics ================================== Message - * Attribute names are identical v - * Attributes are identical v - * ADAT dimensions are identical v - * ADAT row names are identical v - * ADATs contain identical Features v - * ADATs contain same Meta Fields v + > Attribute names are identical v + > Attributes are identical v + > ADAT dimensions are identical v + > ADAT row names are identical v + > ADATs contain identical Features v + > ADATs contain same Meta Fields v Output -- Checking the data matrix ---------------------------------------------------- Message - * All Clinical data is identical v - * All Feature data is identical v + > All Clinical data is identical v + > All Feature data is identical v Output ================================================================================ diff --git a/tests/testthat/_snaps/is-intact-attr.md b/tests/testthat/_snaps/is-intact-attr.md index 5a589c9..819a3dc 100644 --- a/tests/testthat/_snaps/is-intact-attr.md +++ b/tests/testthat/_snaps/is-intact-attr.md @@ -3,7 +3,7 @@ Code is_intact_attr(iris, verbose = TRUE) Message - x The object is not a `soma_adat` class object: 'data.frame' + x The object is not a `soma_adat` class object: "data.frame" Output [1] FALSE @@ -19,7 +19,7 @@ Code is_intact_attr(iris) Message - x The object is not a `soma_adat` class object: 'data.frame' + x The object is not a `soma_adat` class object: "data.frame" Output [1] FALSE diff --git a/tests/testthat/_snaps/loadAdatsAsList.md b/tests/testthat/_snaps/loadAdatsAsList.md index 90f0d4a..113edef 100644 --- a/tests/testthat/_snaps/loadAdatsAsList.md +++ b/tests/testthat/_snaps/loadAdatsAsList.md @@ -15,15 +15,15 @@ Code bad <- loadAdatsAsList(c(files, "fail.adat")) Message - x Failed to load: 'fail.adat' + x Failed to load: "fail.adat" --- Code bad2 <- loadAdatsAsList(c("a.adat", "b.adat")) Message - x Failed to load: 'a.adat' - x Failed to load: 'b.adat' + x Failed to load: "a.adat" + x Failed to load: "b.adat" # collapsed ADATs attributes (HEADER) are correctly merged