Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upkeep - fix doc issues + update CI + drop crayon #77

Merged
merged 15 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")'
65 changes: 21 additions & 44 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# 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 @@ -36,38 +37,14 @@ jobs:
extra-packages: any::pkgdown, local::.
needs: website

- name: Install package
run: R CMD INSTALL .

- name: Build and deploy pkgdown site
if: contains(env.isPush, 'true')
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
- name: Create website
if: contains(env.isPush, 'false')
run: |
pkgdown::build_site()
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Create index file
if: contains(env.isPush, 'false')
run: |
echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;URL=/dev/index.html" /> <script language="javascript"> window.location.replace('/dev/index.html')</script></head></html>' > ./docs/index.html
- name: Deploy to Netlify
if: contains(env.isPush, 'false')
id: netlify-deploy
uses: nwtgck/[email protected]
- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
publish-dir: './docs'
production-branch: master
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message:
'Deploy from GHA: ${{ github.event.pull_request.title || github.event.head_commit.message }} (${{ github.sha }})'
# these all default to 'true'
enable-pull-request-comment: false
enable-commit-comment: false
# enable-commit-status: true
#o verwrites-pull-request-comment: true
timeout-minutes: 1
clean: false
branch: gh-pages
folder: docs
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
16 changes: 8 additions & 8 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.5.0),
olivroy marked this conversation as resolved.
Show resolved Hide resolved
cli,
generics,
jtools (>= 2.0.3),
Expand All @@ -26,20 +26,20 @@ 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
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
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 @@ -443,11 +443,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
16 changes: 9 additions & 7 deletions R/johnson_neyman.R
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ johnson_neyman <- function(model, pred, modx, vmat = NULL, alpha = 0.05,
ggplot2::geom_segment(ggplot2::aes(x = modrangeo[1], xend = modrangeo[2],
y = 0, yend = 0,
linetype = "Range of\nobserved\ndata"),
lineend = "square", size = 1.25)
lineend = "square", linewidth = 1.25)
}

# Adding this scale allows me to have consistent ordering
Expand Down Expand Up @@ -603,17 +603,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 @@ -622,13 +621,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
Loading