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

Correct examples using suggests packages to run conditionally #78

Merged
merged 18 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
60 changes: 60 additions & 0 deletions .github/workflows/check-no-suggests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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: check-no-suggests.yaml

permissions: read-all

jobs:
check-no-suggests:
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")'
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export(odds)
export(odds_ratio)
export(odds_ratio2)
export(par_pattern)
export(params)
export(pbern)
export(pextreme)
export(phi)
Expand Down
3 changes: 2 additions & 1 deletion R/dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,12 @@ dev_pois_zi <- function(x, lambda, prob = 0, res = FALSE) {
#' @family dev_dist
#' @export
#'
#' @examples
#' @examplesIf requireNamespace("sn")
#' dev_skewnorm(c(-2:2))
#' dev_skewnorm(-2:2, 0, 1, 5)
#' dev_skewnorm(-2:2, 0, 1, 5, res = TRUE)
dev_skewnorm <- function(x, mean = 0, sd = 1, shape = 0, res = FALSE) {
rlang::check_installed("sn")
delta <- shape / sqrt(1 + shape^2)
mu_z <- sqrt(2 / pi) * delta
sig_z <- sqrt(1 - mu_z^2)
Expand Down
2 changes: 2 additions & 0 deletions R/extras-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"_PACKAGE"

## usethis namespace: start
#' @import chk
#' @importFrom stats dbinom dlnorm dnorm dpois dnbinom
## usethis namespace: end
NULL
1 change: 1 addition & 0 deletions R/fabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#'
#' @param x An existing R object.
#' @family translations
#' @return A numeric vector of the corresponding absolute values.
#' @export
#' @examples
#' fabs(c(0, -1, 2))
Expand Down
3 changes: 2 additions & 1 deletion R/log-lik.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,12 @@ log_lik_pois_zi <- function(x, lambda = 1, prob = 0) {
#' @family log_lik_dist
#' @export
#'
#' @examples
#' @examplesIf requireNamespace("sn")
#' log_lik_skewnorm(c(-2:2))
#' log_lik_skewnorm(c(-2:2), shape = -2)
#' log_lik_skewnorm(c(-2:2), shape = 2)
log_lik_skewnorm <- function(x, mean = 0, sd = 1, shape = 0) {
rlang::check_installed("sn")
log_lik <- dskewnorm(x = x, mean = mean, sd = sd, shape = shape, log = TRUE)
use_norm <- !is.na(shape) & shape == 0
lnorm <- log_lik_norm(x = x, mean = mean, sd = sd)
Expand Down
3 changes: 0 additions & 3 deletions R/namespace.R

This file was deleted.

1 change: 1 addition & 0 deletions R/numericise.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ numericise.POSIXct <- function(x, ...) {
#' @examples
#'
#' # hms
#' @examplesIf requireNamespace("hms")
#' numericise(hms::as_hms("00:01:03"))
numericise.hms <- function(x, ...) {
# I'm not sure if this test is needed since S3 function
Expand Down
1 change: 1 addition & 0 deletions R/params.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#' @param x An object.
#' @aliases parameters arguments args
#' @usage NULL
#' @export
# nocov start
params <- function(...) NULL
# nocov end
3 changes: 2 additions & 1 deletion R/ran.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ ran_pois_zi <- function(n = 1, lambda = 1, prob = 0) {
#' @family ran_dist
#' @export
#'
#' @examples
#' @examplesIf requireNamespace("sn")
#' ran_skewnorm(10, shape = -1)
#' ran_skewnorm(10, shape = 0)
#' ran_skewnorm(10, shape = 1)
ran_skewnorm <- function(n = 1, mean = 0, sd = 1, shape = 0) {
rlang::check_installed("sn")
chk_whole_number(n)
chk_gte(n)
rskewnorm(n = n, mean = mean, sd = sd, shape = shape)
Expand Down
3 changes: 2 additions & 1 deletion R/res.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,10 @@ res_student_standardized <- function(x, mean, sd, theta) {
#' @family res_dist
#' @export
#'
#' @examples
#' @examplesIf requireNamespace("sn")
#' res_skewnorm(c(-2:2))
res_skewnorm <- function(x, mean = 0, sd = 1, shape = 0, type = "dev", simulate = FALSE) {
rlang::check_installed("sn")
chk_string(type)
if (!vld_false(simulate)) {
x <- ran_skewnorm(length(x), mean = mean, sd = sd, shape = shape)
Expand Down
2 changes: 1 addition & 1 deletion R/sens.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ sens_student <- function(mean, sd, theta, sd_mult = 2) {
#' @family sens_dist
#' @export
#'
#' @examples
#' @examplesIf requireNamespace("sn")
#' sens_skewnorm(10, 3, -1, 2)
#' sens_skewnorm(10, 3, 3, 0.8)
sens_skewnorm <- function(mean, sd, shape, sd_mult = 2) {
Expand Down
30 changes: 5 additions & 25 deletions R/skewnorm.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @rdname skewnorm
#' @export
#'
#' @examples
#' @examplesIf requireNamespace("sn")
#' dskewnorm(x = -2:2, mean = 0, sd = 1, shape = 0.1)
#' dskewnorm(x = -2:2, mean = 0, sd = 1, shape = -1)
#' qskewnorm(p = c(0.1, 0.4), mean = 0, sd = 1, shape = 0.1)
Expand All @@ -20,12 +20,7 @@
#' rskewnorm(n = 3, mean = 0, sd = 1, shape = 0.1)
#' rskewnorm(n = 3, mean = 0, sd = 1, shape = -1)
dskewnorm <- function(x, mean = 0, sd = 1, shape = 0, log = FALSE) {
if (!requireNamespace("sn", quietly = TRUE)) {
stop(
"Package \"sn\" must be installed to use this function.",
call. = FALSE
)
}
rlang::check_installed("sn")
chk_gte(sd)
nulls <- any(is.null(x), is.null(mean), is.null(sd), is.null(shape))
if (nulls) stop("invalid arguments")
Expand All @@ -49,12 +44,7 @@ dskewnorm <- function(x, mean = 0, sd = 1, shape = 0, log = FALSE) {
#' @rdname skewnorm
#' @export
pskewnorm <- function(q, mean = 0, sd = 1, shape = 0) {
if (!requireNamespace("sn", quietly = TRUE)) {
stop(
"Package \"sn\" must be installed to use this function.",
call. = FALSE
)
}
rlang::check_installed("sn")
chk_gte(sd)
nulls <- any(is.null(q), is.null(mean), is.null(sd), is.null(shape))
if (nulls) stop("invalid arguments")
Expand All @@ -78,12 +68,7 @@ pskewnorm <- function(q, mean = 0, sd = 1, shape = 0) {
#' @rdname skewnorm
#' @export
qskewnorm <- function(p, mean = 0, sd = 1, shape = 0) {
if (!requireNamespace("sn", quietly = TRUE)) {
stop(
"Package \"sn\" must be installed to use this function.",
call. = FALSE
)
}
rlang::check_installed("sn")
chk_gte(sd)
chk_gte(p)
chk_lte(p, 1)
Expand Down Expand Up @@ -112,12 +97,7 @@ qskewnorm <- function(p, mean = 0, sd = 1, shape = 0) {
#' @rdname skewnorm
#' @export
rskewnorm <- function(n = 1, mean = 0, sd = 1, shape = 0) {
if (!requireNamespace("sn", quietly = TRUE)) {
stop(
"Package \"sn\" must be installed to use this function.",
call. = FALSE
)
}
rlang::check_installed("sn")
chk_gte(n)
chk_lt(n, Inf)
chk_not_any_na(n)
Expand Down
29 changes: 2 additions & 27 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
## Test environments

release 4.4.1

* OSX (local) - release
* OSX (actions) - release
* OSX (R-hub) - devel
* Ubuntu (actions) - oldrel-1, release, and devel
* Ubuntu (R-hub) - devel
* Fedora (R-hub)
* Windows (actions) - release
* Windows (winbuilder) - devel
* Windows (R-hub) - devel

## R CMD check results

0 errors | 0 warnings | 1 note

New maintainer:
Nicole Hill <[email protected]>
Old maintainer(s):
Joe Thorley <[email protected]>
0 errors | 0 warnings | 0 notes

## CRAN Issues

Fixed the following error by conditionally skipping tests that rely on packages listed in suggests, if those packages are not installed.
After review, also decided to remove the dependency to the 'aods3' package.

══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-log-lik.R:184:3'): beta_binom log_lik ──────────────────────────
<packageNotFoundError/error/condition>
Error in `loadNamespace(x)`: there is no package called 'aods3'
After feedback, corrected the noSuggests issue to have all tests, examples, and vignettes run conditionally for packages listed under Suggests.

## revdepcheck results

Expand Down
2 changes: 1 addition & 1 deletion inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Summarise
Surprisal
TMB
WinBUGS
behaviour
bern
bigg
cdot
Expand All @@ -24,7 +25,6 @@ lik
modelling
numericise
skewnorm
styler
summarise
surprisal
testthat
Expand Down
2 changes: 2 additions & 0 deletions man/dev_skewnorm.Rd

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

3 changes: 3 additions & 0 deletions man/fabs.Rd

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

2 changes: 2 additions & 0 deletions man/log_lik_skewnorm.Rd

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

2 changes: 2 additions & 0 deletions man/numericise.Rd

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

6 changes: 0 additions & 6 deletions man/params.Rd

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

2 changes: 2 additions & 0 deletions man/ran_skewnorm.Rd

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

2 changes: 2 additions & 0 deletions man/res_skewnorm.Rd

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

2 changes: 2 additions & 0 deletions man/sens_skewnorm.Rd

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

2 changes: 2 additions & 0 deletions man/skewnorm.Rd

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

Loading
Loading