Skip to content

Commit

Permalink
Fix crayon bug and ui_bullet issue (#130)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
scheidec authored Sep 24, 2024
1 parent 9586713 commit 331300d
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 118 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,6 +40,7 @@ Suggests:
rmarkdown,
spelling,
testthat (>= 3.0.0),
usethis (>= 2.0.1),
withr
VignetteBuilder:
knitr
Expand All @@ -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
2 changes: 1 addition & 1 deletion R/diffAdats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}

Expand Down
10 changes: 5 additions & 5 deletions R/is-intact-attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions R/loadAdatsAsList.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
12 changes: 6 additions & 6 deletions R/parseCheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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")
Expand All @@ -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")) ) {
Expand All @@ -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"))
}
2 changes: 1 addition & 1 deletion R/prepHeaderMeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) ) {
Expand Down
24 changes: 12 additions & 12 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -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}}")
}
}

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/write-adat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 1 addition & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
Loading

0 comments on commit 331300d

Please sign in to comment.