Skip to content

Commit

Permalink
Improve package behavior when Suggestions are not installed (#48)
Browse files Browse the repository at this point in the history
* Make some tests conditionnal
* Make some tests conditionnal
* Make some part of vignettes conditionnal
  • Loading branch information
cedricbatailler authored Feb 27, 2024
1 parent 065222b commit 9636065
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 8 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/check-no-suggests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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
#
# NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends,
# Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never
# installed, with the exception of testthat, knitr, and rmarkdown. The cache is
# never used to avoid accidentally restoring a cache containing a suggested
# dependency.
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check-hard

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, r: 'release'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- 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-r-dependencies@v2
with:
dependencies: '"hard"'
cache: false
extra-packages: |
any::rcmdcheck
any::testthat
any::knitr
any::rmarkdown
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## Minor improvements and bug fixes

* Some tests, examples, and parts of the vignettes are now conditionnal
* Fix issues related to assumption check functions
* Small maintenance task
* Fix some typos in documentation
* Small maintenance tasks

# JSmediation (0.2.1)

Expand Down
5 changes: 4 additions & 1 deletion R/check_assumptions.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
#'
#' @return Invisibly returns an object of class \code{mediation_model}.
#'
#' @examples
#' @examplesIf rlang::is_installed("performance")
#'
#' data(ho_et_al)
#'
#' ho_et_al$condition_c <- build_contrast(ho_et_al$condition,
#' "Low discrimination",
#' "High discrimination")
#'
#' my_model <-
#' mdt_simple(data = ho_et_al,
#' IV = condition_c,
Expand Down
5 changes: 4 additions & 1 deletion R/plot_assumptions.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
#'
#' @return Invisibly returns an object of class \code{mediation_model}.
#'
#' @examples
#' @examplesIf rlang::is_installed("see")
#'
#' data(ho_et_al)
#'
#' ho_et_al$condition_c <- build_contrast(ho_et_al$condition,
#' "Low discrimination",
#' "High discrimination")
#'
#' my_model <-
#' mdt_simple(data = ho_et_al,
#' IV = condition_c,
Expand Down
6 changes: 5 additions & 1 deletion man/check_assumptions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/plot_assumptions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/testthat/test-check_assumptions.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("performance")

test_that("check_assumptions run without error", {
ho_et_al$condition_c <- build_contrast(ho_et_al$condition,
"Low discrimination",
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-plot_assumptions.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("see")

test_that("check_assumptions_plot", {
# it seems that check models produce some error which are not relevent for
# the test.
Expand Down
6 changes: 3 additions & 3 deletions vignettes/jsmediation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ regard. This function uses a mediation model as a first argument, and the model
name (or model index) as a second argument. It then returns a linear model
object (i.e., an `lm` object).

```{r fig.height=8, fig.width=7, out.width="100%"}
```{r eval=rlang::is_installed("performance"), fig.height=8, fig.width=7, out.width="100%"}
first_model <- extract_model(mediation_fit, step = "X -> M")
performance::check_model(first_model)
```

We will do the same thing for the two other models mdt_simple has fitted.

```{r fig.height=8, fig.width=7, out.width="100%"}
```{r eval=rlang::is_installed("performance"), fig.height=8, fig.width=7, out.width="100%"}
second_model <- extract_model(mediation_fit, step = 2)
performance::check_model(second_model)
```

```{r fig.height=8, fig.width=7, out.width="100%"}
```{r eval=rlang::is_installed("performance"), fig.height=8, fig.width=7, out.width="100%"}
third_model <- extract_model(mediation_fit, step = 3)
performance::check_model(third_model)
```
Expand Down

0 comments on commit 9636065

Please sign in to comment.