-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from randrescastaneda/style_msg
messages and update github actions
- Loading branch information
Showing
16 changed files
with
426 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
branches: [main, master] | ||
pull_request: | ||
branches: | ||
- main | ||
- master | ||
branches: [main, master] | ||
|
||
name: test-coverage | ||
|
||
jobs: | ||
test-coverage: | ||
runs-on: macOS-latest | ||
runs-on: ubuntu-latest | ||
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 | ||
with: | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-pandoc@v1 | ||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::covr | ||
needs: coverage | ||
|
||
- name: Query dependencies | ||
- name: Test coverage | ||
run: | | ||
install.packages('remotes') | ||
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) | ||
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") | ||
covr::codecov( | ||
quiet = FALSE, | ||
clean = FALSE, | ||
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") | ||
) | ||
shell: Rscript {0} | ||
|
||
- name: Restore R package cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ env.R_LIBS_USER }} | ||
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} | ||
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- | ||
|
||
- name: Install dependencies | ||
- name: Show testthat output | ||
if: always() | ||
run: | | ||
install.packages(c("remotes")) | ||
remotes::install_deps(dependencies = TRUE) | ||
remotes::install_cran("covr") | ||
shell: Rscript {0} | ||
## -------------------------------------------------------------------- | ||
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true | ||
shell: bash | ||
|
||
- name: Test coverage | ||
run: covr::codecov() | ||
shell: Rscript {0} | ||
- name: Upload test results | ||
if: failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: coverage-test-failures | ||
path: ${{ runner.temp }}/package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.joynenv <- new.env(parent = emptyenv()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#' display type of joyn message | ||
#' | ||
#' @param type character: one or more of `c("all", "info", "note", "warn", "timing")` | ||
#' | ||
#' @return returns data frame with message invisibly. print message in console | ||
#' @export | ||
#' | ||
#' @examples | ||
#' joyn:::store_msg("info", ok = cli::symbol$tick, " ", pale = "This is an info message") | ||
#' joyn:::store_msg("warn", err = cli::symbol$cross, " ", note = "This is a warning message") | ||
#' joyn_msg("all") | ||
joyn_msg <- function(type = c("all", "info", "note", "warn", "timing")) { | ||
|
||
# Check --------- | ||
type_to_use <- match.arg(type, several.ok = TRUE) | ||
joyn_msgs_exist() | ||
|
||
# get msgs --------- | ||
dt <- rlang::env_get(.joynenv, "joyn_msgs") | ||
|
||
if ("all" %!in% type_to_use) { | ||
dt <- dt |> | ||
fsubset(type %in% type_to_use) | ||
} | ||
|
||
# display results -------- | ||
# cat(dt[["msg"]], "\n", sep = "\n") | ||
l <- lapply(dt[["msg"]], \(.) { | ||
cli::cli_text(.) | ||
}) | ||
|
||
|
||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Return --------- | ||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
return(invisible(dt)) | ||
} | ||
|
||
|
||
#' Store joyn message to .joynenv environment | ||
#' | ||
#' @inheritParams joyn_msg | ||
#' @param ... combination of type and text in the form `style1 = text1, style2 = | ||
#' text2`, etc. | ||
#' | ||
#' @return current message data frame invisibly | ||
#' @keywords internal | ||
store_msg <- function(type, ...) { | ||
|
||
# check input ---------- | ||
type <- match.arg(type, choices = c("info", "note", "warn", "timing")) | ||
check_style(...) | ||
|
||
# style type in dt form ----------- | ||
dt_msg <- msg_type_dt(type, ...) | ||
|
||
# create new messages --------- | ||
if (rlang::env_has(.joynenv, "joyn_msgs")) { | ||
dt_old_msgs <- rlang::env_get(.joynenv, "joyn_msgs") | ||
dt_new_msgs <- rowbind(dt_old_msgs, dt_msg) | ||
} else { | ||
dt_new_msgs <- dt_msg | ||
} | ||
|
||
# store in env ------ | ||
rlang::env_poke(.joynenv, "joyn_msgs", dt_new_msgs) | ||
|
||
|
||
# Return --------- | ||
return(invisible(dt_new_msgs)) | ||
|
||
} | ||
|
||
check_style <- \(...) { | ||
if (length(list(...)) == 0) { | ||
cli::cli_abort(c("no style provided", | ||
"i" = "check list of styles in {.fun style}")) | ||
} | ||
invisible(TRUE) | ||
} | ||
|
||
#' convert style to data frame | ||
#' | ||
#' @inheritParams joyn_msg | ||
#' | ||
#' @return data frame | ||
#' @keywords internal | ||
msg_type_dt <- \(type, ...) { | ||
c(type = type, msg = style(...)) |> # named vector | ||
as.list() |> # convert to list to pass as data.frame | ||
data.frame() # convert | ||
} | ||
|
||
|
||
#' style of text displayed | ||
#' | ||
#' This is from | ||
#' https://github.com/r-lib/pkgbuild/blob/3ba537ab8a6ac07d3fe11c17543677d2a0786be6/R/styles.R | ||
#' @param ... combination of type and text in the form `type1 = text1, type2 = text2` | ||
#' @param sep a character string to separate the terms to [paste] | ||
#' | ||
#' @return formated text | ||
#' @keywords internal | ||
style <- function(..., sep = "") { | ||
args <- list(...) | ||
# st <- names(args) | ||
|
||
styles <- list( | ||
"ok" = cli::col_green, | ||
"note" = cli::make_ansi_style("orange"), | ||
"warn" = \(x) { | ||
cli::make_ansi_style("#cc6677")(x) |> | ||
cli::style_bold() | ||
}, | ||
"err" = cli::col_red, | ||
"pale" = cli::make_ansi_style("darkgrey"), | ||
"timing" = cli::make_ansi_style("cyan") | ||
) | ||
|
||
nms <- names(args) | ||
x <- lapply(seq_along(args), \(i) { | ||
if (nzchar(nms[i])) { | ||
|
||
styles[[nms[i]]](args[[i]]) | ||
|
||
} else { | ||
|
||
args[[i]] | ||
|
||
} | ||
}) | ||
|
||
paste(unlist(x), collapse = sep) | ||
} | ||
|
||
|
||
joyn_msgs_exist <- \() { | ||
if (!rlang::env_has(.joynenv, "joyn_msgs")) { | ||
cli::cli_abort(c("no messages stored in .joynenv", | ||
"i" = "make sure that joyn has been executed at least once")) | ||
} | ||
invisible(TRUE) | ||
} | ||
|
||
|
||
clear_joynenv <- \(){ | ||
rlang::env_unbind(.joynenv, "joyn_msgs") | ||
invisible(TRUE) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
#' @import data.table | ||
#' @import collapse | ||
## usethis namespace: end | ||
# .datatable.aware = TRUE | ||
|
||
# Prevent R CMD check from complaining about the use of pipe expressions | ||
# standard data.table variables | ||
if (getRversion() >= "2.15.1") { | ||
utils::globalVariables( | ||
names = c( | ||
".", | ||
".I", | ||
".N", | ||
".SD", | ||
".", | ||
"!!", | ||
":=", | ||
"..output", | ||
"x_report", | ||
"y_report" | ||
), | ||
package = utils::packageName() | ||
) | ||
} | ||
|
||
NULL |
Oops, something went wrong.