Skip to content

Commit

Permalink
Merge pull request #26 from randrescastaneda/style_msg
Browse files Browse the repository at this point in the history
messages and update github actions
  • Loading branch information
randrescastaneda authored Nov 30, 2023
2 parents 674ebac + d175d3e commit 831e931
Show file tree
Hide file tree
Showing 16 changed files with 426 additions and 90 deletions.
77 changes: 20 additions & 57 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
# 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: R-CMD-check

Expand All @@ -22,65 +18,32 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-pandoc@v1

- name: Query dependencies
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")
shell: Rscript {0}

- name: Restore R package cache
if: runner.os != 'Windows'
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@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 system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}
extra-packages: any::rcmdcheck
needs: check

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
60 changes: 31 additions & 29 deletions .github/workflows/test-coverage.yaml
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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ Imports:
glue,
cli,
stats,
utils
utils,
collapse (>= 2.0.6)
Depends:
R (>= 2.10)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

export(freq_table)
export(is_id)
export(joyn_msg)
export(merge)
export(possible_ids)
import(collapse)
import(data.table)
1 change: 1 addition & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.joynenv <- new.env(parent = emptyenv())
150 changes: 150 additions & 0 deletions R/info_display.R
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)
}

30 changes: 30 additions & 0 deletions R/joyn-package.R
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
Loading

0 comments on commit 831e931

Please sign in to comment.