Skip to content

Commit

Permalink
Merge pull request #77 from olivroy/upkeep
Browse files Browse the repository at this point in the history
Upkeep - fix doc issues + update CI + drop crayon
  • Loading branch information
jacob-long authored Jul 28, 2024
2 parents 6a9b659 + 45edf27 commit 38ae938
Show file tree
Hide file tree
Showing 24 changed files with 260 additions and 257 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
^hex\.png$
^LICENSE\.md$
^\.github$
^pkgdown$
^pkgdown$
^interactions\.Rproj$
32 changes: 9 additions & 23 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# 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:
Expand All @@ -8,6 +8,8 @@ on:

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -18,7 +20,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -29,7 +31,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

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

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

Expand All @@ -41,26 +43,10 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck

- name: Set CRAN mirror
run: echo "options(repos = c(CRAN='https://cloud.r-project.org/'))" > ~/.Rprofile
extra-packages: any::rcmdcheck
needs: check

- name: Install lme4 from source to fix Matrix errors
run: |
install.packages('lme4', type = 'source')
shell: Rscript {0}

- uses: r-lib/actions/check-r-package@v2

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
28 changes: 15 additions & 13 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
# Jacob copied from https://github.com/r-lib/pkgdown/blob/main/.github/workflows/pkgdown.yaml
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# 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]
tags: ['*']
pull_request:
branches: [master, main]
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

permissions: read-all

jobs:
pkgdown:
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork == false
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
isPush: ${{ github.event_name == 'push' }}

permissions:
contents: write
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-tinytex@v2
- uses: actions/checkout@v4

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

Expand All @@ -38,7 +40,7 @@ jobs:

- name: Install package
run: R CMD INSTALL .

- name: Build and deploy pkgdown site
if: contains(env.isPush, 'true')
run: |
Expand All @@ -50,7 +52,7 @@ jobs:
run: |
pkgdown::build_site()
shell: Rscript {0}

- name: Create index file
if: contains(env.isPush, 'false')
run: |
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,54 @@ on:

name: test-coverage

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

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

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
covr::codecov(
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
14 changes: 7 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ URL: https://interactions.jacob-long.com
BugReports: https://github.com/jacob-long/interactions/issues
License: MIT + file LICENSE
Encoding: UTF-8
Imports: ggplot2,
crayon,
Imports:
ggplot2 (>= 3.4.0),
cli,
generics,
jtools (>= 2.0.3),
Expand All @@ -26,17 +26,17 @@ Imports: ggplot2,
Suggests:
broom,
cowplot,
ggstance,
broom.mixed,
glue,
huxtable (>= 3.0.0),
lme4,
margins,
sandwich,
survey,
knitr,
rmarkdown,
testthat,
vdiffr
knitr,
rmarkdown,
testthat,
vdiffr
Enhances:
brms,
rstanarm
Expand Down
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ import(jtools)
import(rlang)
importFrom(cli,cat_rule)
importFrom(cli,rule)
importFrom(crayon,bold)
importFrom(crayon,inverse)
importFrom(crayon,italic)
importFrom(crayon,red)
importFrom(crayon,underline)
importFrom(generics,glance)
importFrom(generics,tidy)
importFrom(stats,aggregate)
Expand Down
17 changes: 10 additions & 7 deletions R/interact_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
#' appears above the legend. If \code{NULL}, the name of the moderating
#' variable is used.
#'
#' @param colors See [jtools_colors] for details on the types of arguments
#' accepted. Default is "CUD Bright" for factor
#' @param colors See [`jtools_colors`][jtools::jtools_colors] for details on the
#' types of arguments accepted. Default is "CUD Bright" for factor
#' moderators, "Blues" for +/- SD and user-specified \code{modx.values}
#' values.
#'
Expand Down Expand Up @@ -446,11 +446,14 @@ interact_plot <- function(model, pred, modx, modx.values = NULL, mod2 = NULL,
# Check for factor predictor and send to plot_cat() if so
if (!is.numeric(d[[pred]])) {
# Warn users that this is kinda janky
msg_wrap("Detected factor predictor. Plotting with cat_plot() instead.
Consult cat_plot() documentation (?cat_plot) for full details
on how to specify models with categorical predictors. If you
experience errors or unexpected results, try using cat_plot()
directly.")
cli::cli_inform(c(
x = "Detected factor predictor.",
i = "Plotting with cat_plot() instead.",
i = "See {.help interactions::cat_plot} for full details on
how to specify models with categorical predictors.",
i = "If you experience errors or unexpected results, try using
cat_plot() directly."
))
# Gather arguments for plot_cat()
args <- list(predictions = pm, pred = pred, modx = modx, mod2 = mod2,
data = d, modx.values = modxvals2, mod2.values = mod2vals2,
Expand Down
14 changes: 8 additions & 6 deletions R/johnson_neyman.R
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,16 @@ johnson_neyman <- function(model, pred, modx, vmat = NULL, alpha = 0.05,
}

#' @export
#' @importFrom crayon bold inverse underline

print.johnson_neyman <- function(x, ...) {

atts <- attributes(x)

# Describe whether sig values are inside/outside the interval
if (atts$inside == FALSE) {
inout <- inverse("OUTSIDE")
inout <- cli::style_inverse("OUTSIDE")
} else {
inout <- inverse("INSIDE")
inout <- cli::style_inverse("INSIDE")
}

b_format <- num_print(x$bounds, atts$digits)
Expand All @@ -641,13 +640,16 @@ print.johnson_neyman <- function(x, ...) {
pmsg <- paste("p <", alpha)

# Print the output
cat(bold(underline("JOHNSON-NEYMAN INTERVAL")), "\n\n")
cli::cat_line(
cli::style_bold(cli::style_underline("JOHNSON-NEYMAN INTERVAL")),
"\n"
)
if (all(is.finite(x$bounds))) {
cat_wrap("When ", atts$modx, " is ", inout, " the interval [",
b_format[1], ", ", b_format[2], "], the slope of ", atts$pred,
" is ", pmsg, ".", brk = "\n\n")
cat_wrap(italic("Note: The range of observed values of", atts$modx,
"is "), "[", m_range[1], ", ", m_range[2], "]", brk = "\n\n")
cat_wrap(cli::style_italic("Note: The range of observed values of ", atts$modx,
" is "), "[", m_range[1], ", ", m_range[2], "]", brk = "\n\n")
} else {
cat_wrap("The Johnson-Neyman interval could not be found.
Is the p value for your interaction term below
Expand Down
10 changes: 6 additions & 4 deletions R/simple_margins.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ sim_margins <- function(model, pred, modx, mod2 = NULL, modx.values = NULL,

#' @export
#' @importFrom cli cat_rule rule
#' @importFrom crayon red bold italic

print.sim_margins <- function(x, ...) {

Expand Down Expand Up @@ -308,7 +307,10 @@ print.sim_margins <- function(x, ...) {
}

# Clearly label simple slopes
cat(bold(underline("SIMPLE MARGINS")), "\n\n")
cli::cat_line(
cli::style_bold(cli::style_underline("SIMPLE MARGINS")),
"\n"
)

for (i in seq_along(x$modx.values)) {

Expand All @@ -329,8 +331,8 @@ print.sim_margins <- function(x, ...) {
modx_label <- paste0(m[i, x$modx])
}

cat(italic(paste0("Average marginal effect of ", x$pred, " when ",
x$modx, " = ", modx_label, ": \n\n")))
cli::cat_line(cli::style_italic(paste0("Average marginal effect of ", x$pred, " when ",
x$modx, " = ", modx_label, ": \n")))
print(md_table(slopes, digits = x$digits, format = "pandoc",
row.names = FALSE, sig.digits = FALSE))

Expand Down
14 changes: 8 additions & 6 deletions R/simple_slopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,6 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL,

#' @export
#' @importFrom cli cat_rule rule
#' @importFrom crayon red bold italic

print.sim_slopes <- function(x, ...) {

Expand Down Expand Up @@ -859,7 +858,10 @@ print.sim_slopes <- function(x, ...) {
}

# Clearly label simple slopes
cat(bold(underline("SIMPLE SLOPES ANALYSIS")), "\n\n")
cli::cat_line(
cli::style_bold(cli::style_underline("SIMPLE SLOPES ANALYSIS")),
"\n"
)

for (i in seq_along(x$modx.values)) {

Expand All @@ -882,7 +884,7 @@ print.sim_slopes <- function(x, ...) {
# Print conditional intercept
if (x$cond.int == TRUE | fac_pred == TRUE) {
pred_lab <- if (fac_pred) {slopes[["Coef."]]} else {x$pred}
cat(italic(paste0("When ", x$modx, " = ", modx_label, ": \n\n")))
cli::cat_line(cli::style_italic(paste0("When ", x$modx, " = ", modx_label, ": \n")))
if (x$cond.int) {
ints <- m$ints[i,2:ncol(m$slopes)]
slopes <- as.data.frame(rbind(slopes, ints))
Expand All @@ -895,8 +897,8 @@ print.sim_slopes <- function(x, ...) {
print(md_table(slopes %not% "Coef.", digits = x$digits,
format = "pandoc", sig.digits = FALSE))
} else {
cat(italic(paste0("Slope of ", x$pred, " when ", x$modx, " = ",
modx_label, ": \n\n")))
cli::cat_line(cli::style_italic(paste0("Slope of ", x$pred, " when ", x$modx, " = ",
modx_label, ": \n")))
print(md_table(slopes, digits = x$digits, format = "pandoc",
row.names = FALSE, sig.digits = FALSE))
}
Expand Down Expand Up @@ -1036,7 +1038,7 @@ nobs.sim_slopes <- function(object, ...) {
#' @param x The [sim_slopes()] object.
#' @param format The method for sharing the slope and associated uncertainty.
#' Default is `"{estimate} ({std.error})"`. See the instructions for the
#' `error_format` argument of [export_summs()] for more on your
#' `error_format` argument of [jtools::export_summs()] for more on your
#' options.
#' @param sig.levels A named vector in which the values are potential p value
#' thresholds and the names are significance markers (e.g., "*") for when
Expand Down
Loading

0 comments on commit 38ae938

Please sign in to comment.