From 7085a10a873dd600d95ed8c5c1967bbe9e0cd84b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franti=C5=A1ek=20Barto=C5=A1?=
<38475991+FBartos@users.noreply.github.com>
Date: Tue, 28 May 2024 14:01:45 +0200
Subject: [PATCH] Fix input check (#24)
* fix: https://github.com/FBartos/zcurve/issues/22
* try fixing CMD check
* Update R-CMD-check.yaml
* update
* update unit tests
* Update test-zcurve.R
* Update R-CMD-tests.yaml
---
.github/workflows/R-CMD-check.yaml | 94 ++++---------------
.github/workflows/R-CMD-tests.yaml | 54 ++++-------
.github/workflows/test-coverage.yaml | 61 ++++++++++++
DESCRIPTION | 2 +-
NEWS.md | 3 +
R/main.R | 10 +-
.../_snaps/zcurve/z-curve-kd2-ggplot.svg | 4 +-
tests/testthat/_snaps/zcurve/z-curve-kd2.svg | 4 +-
tests/testthat/test-zcurve.R | 34 +++----
9 files changed, 132 insertions(+), 134 deletions(-)
create mode 100644 .github/workflows/test-coverage.yaml
diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml
index 237cc7b..f4a4f91 100644
--- a/.github/workflows/R-CMD-check.yaml
+++ b/.github/workflows/R-CMD-check.yaml
@@ -1,19 +1,15 @@
-# 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
- - pre-release
+ branches: [main, master]
pull_request:
- branches:
- - main
- - master
- - pre-release
+ branches: [main, master]
name: R-CMD-check
+permissions: read-all
+
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
@@ -24,82 +20,32 @@ jobs:
fail-fast: false
matrix:
config:
+ - {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- - {os: macOS-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
+ - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
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@v3
+ - 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-pandoc@v2
-
- - 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
- 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
- sudo apt-get install libcurl4-openssl-dev
-
- - name: Install dependencies
- run: |
- remotes::install_deps(dependencies = TRUE)
- remotes::install_cran("rcmdcheck")
- shell: Rscript {0}
-
- - name: Check
- if: runner.os != 'Windows'
- env:
- _R_CHECK_CRAN_INCOMING_REMOTE_: false
- run: |
- options(crayon.enabled = TRUE)
- rcmdcheck::rcmdcheck(
- args = c("--no-manual", "--as-cran", "--ignore-vignettes"),
- build_args = c("--no-build-vignettes"),
- error_on = "warning",
- check_dir = "check")
- shell: Rscript {0}"
-
- - name: Check
- if: runner.os == 'Windows'
- env:
- _R_CHECK_CRAN_INCOMING_REMOTE_: false
- run: |
- options(crayon.enabled = TRUE)
- rcmdcheck::rcmdcheck(
- args = c("--no-manual", "--as-cran", "--ignore-vignettes"),
- build_args = c("--no-build-vignettes"),
- 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
+ build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
diff --git a/.github/workflows/R-CMD-tests.yaml b/.github/workflows/R-CMD-tests.yaml
index d2682c1..0ccf338 100644
--- a/.github/workflows/R-CMD-tests.yaml
+++ b/.github/workflows/R-CMD-tests.yaml
@@ -1,19 +1,15 @@
-# 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
- - pre-release
+ branches: [main, master]
pull_request:
- branches:
- - main
- - master
- - pre-release
+ branches: [main, master]
name: R-CMD-tests
+permissions: read-all
+
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
@@ -24,50 +20,36 @@ jobs:
fail-fast: false
matrix:
config:
+ - {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- - {os: macOS-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
+ - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
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@v3
+ - 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-pandoc@v2
-
- - 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
- 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
-
+ extra-packages: any::rcmdcheck
+ needs: check
- name: Install and test z-curve (non-Windows)
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
+ install.packages("remotes")
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
install.packages("devtools")
diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml
new file mode 100644
index 0000000..fefc52e
--- /dev/null
+++ b/.github/workflows/test-coverage.yaml
@@ -0,0 +1,61 @@
+# 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]
+ pull_request:
+ branches: [main, master]
+
+name: test-coverage
+
+permissions: read-all
+
+jobs:
+ test-coverage:
+ runs-on: ubuntu-latest
+ env:
+ GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
+
+ steps:
+ - 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, any::xml2
+ needs: coverage
+
+ - name: Test coverage
+ run: |
+ cov <- covr::package_coverage(
+ quiet = FALSE,
+ clean = FALSE,
+ 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
+ shell: bash
+
+ - name: Upload test results
+ if: failure()
+ uses: actions/upload-artifact@v4
+ with:
+ name: coverage-test-failures
+ path: ${{ runner.temp }}/package
diff --git a/DESCRIPTION b/DESCRIPTION
index 21800d2..88afdce 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: zcurve
Title: An Implementation of Z-Curves
-Version: 2.4.1
+Version: 2.4.2
Authors@R: c(
person("František", "Bartoš", email = "f.bartos96@gmail.com", role = c("aut", "cre")),
person("Ulrich", "Schimmack", email = "ulrich.schimmack@utoronto.ca", role = c("aut")))
diff --git a/NEWS.md b/NEWS.md
index d86cc07..cd8d3d9 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,6 @@
+## version 2.4.2
+- Fixes https://github.com/FBartos/zcurve/issues/22
+
## version 2.4.1
- Fixes ODR computation with censored data
diff --git a/R/main.R b/R/main.R
index 8ec6603..bc05dca 100644
--- a/R/main.R
+++ b/R/main.R
@@ -92,19 +92,23 @@ zcurve <- function(z, z.lb, z.ub, p, p.lb, p.ub, data, method = "EM", boot
if(missing(z) & missing(p) & missing(z.lb) & missing(p.lb))
stop("No data input")
if(!missing(z)){
+ if(length(z) == 0)
+ stop("An empty input was passed as z-scores.")
if(!is.numeric(z))
stop("Wrong z-scores input: Data are not nummeric.")
if(!is.vector(z))
- stop("Wrong z-scores input: Data are not a vector")
+ stop("Wrong z-scores input: Data are not a vector.")
if(all(z <= 1 & z >= 0))
- stop("It looks like you are entering p-values rather than z-scores. To use p-values, explicitly name your argument 'zcurve(p = [vector of p-values])'")
+ stop("It looks like you are entering p-values rather than z-scores. To use p-values, explicitly name your argument 'zcurve(p = [vector of p-values])'.")
input_type <- c(input_type, "z")
}
if(!missing(p)){
+ if(length(p) == 0)
+ stop("An empty input was passed as p-values.")
if(!is.numeric(p))
stop("Wrong p-values input: Data are not nummeric.")
if(!is.vector(p))
- stop("Wrong p-values input: Data are not a vector")
+ stop("Wrong p-values input: Data are not a vector.")
input_type <- c(input_type, "p")
}
}else if(inherits(data, "zcurve_data")){
diff --git a/tests/testthat/_snaps/zcurve/z-curve-kd2-ggplot.svg b/tests/testthat/_snaps/zcurve/z-curve-kd2-ggplot.svg
index 83ea8dc..32ca38d 100644
--- a/tests/testthat/_snaps/zcurve/z-curve-kd2-ggplot.svg
+++ b/tests/testthat/_snaps/zcurve/z-curve-kd2-ggplot.svg
@@ -56,10 +56,10 @@
-
+
-
+
diff --git a/tests/testthat/_snaps/zcurve/z-curve-kd2.svg b/tests/testthat/_snaps/zcurve/z-curve-kd2.svg
index 50e38d5..b129144 100644
--- a/tests/testthat/_snaps/zcurve/z-curve-kd2.svg
+++ b/tests/testthat/_snaps/zcurve/z-curve-kd2.svg
@@ -87,9 +87,9 @@
-
+
-
+
diff --git a/tests/testthat/test-zcurve.R b/tests/testthat/test-zcurve.R
index 2d94d89..49c8ca7 100644
--- a/tests/testthat/test-zcurve.R
+++ b/tests/testthat/test-zcurve.R
@@ -59,14 +59,16 @@ test_that("z-curve EM can be fitted and reproduces OSC results", {
))
# plot
- expect_doppelganger("z-curve EM", function()plot(fit.EM, main = "OSC (with EM)", annotation = TRUE, CI = TRUE))
- expect_doppelganger("z-curve EM (ggplot)", suppressWarnings(plot(fit.EM, main = "OSC (with EM)", annotation = TRUE, CI = TRUE, plot_type = "ggplot")))
+ skip_on_os("mac")
+ vdiffr::expect_doppelganger("z-curve EM", function()plot(fit.EM, main = "OSC (with EM)", annotation = TRUE, CI = TRUE))
+ vdiffr::expect_doppelganger("z-curve EM (ggplot)", suppressWarnings(plot(fit.EM, main = "OSC (with EM)", annotation = TRUE, CI = TRUE, plot_type = "ggplot")))
})
test_that("z-curve KD2 can be fitted and reproduces OSC results", {
-
+
# set seed for reproducibility
set.seed(666)
+ skip_on_os("mac")
# fit the EM method
fit.KD2 <- zcurve(OSC.z, method = "density", bootstrap = 10)
@@ -79,7 +81,7 @@ test_that("z-curve KD2 can be fitted and reproduces OSC results", {
"" ,
"Estimates:" ,
" ERR EDR " ,
- "0.6133950 0.5064392 "
+ "0.6133975 0.5064694 "
))
# basic summary
@@ -94,14 +96,14 @@ test_that("z-curve KD2 can be fitted and reproduces OSC results", {
"ERR 0.613 0.496 0.745" ,
"EDR 0.506 0.141 0.714" ,
"" ,
- "Model converged in 47 iterations" ,
+ "Model converged in 46 iterations" ,
"Fitted using 73 z-values. 90 supplied, 85 significant (ODR = 0.94, 95% CI [0.87, 0.98]).",
"RMSE = 0.11, 95% CI[0.09, 0.19]"
))
# plot
- expect_doppelganger("z-curve KD2", function()plot(fit.KD2))
- expect_doppelganger("z-curve KD2 (ggplot)", plot(fit.KD2, plot_type = "ggplot"))
+ vdiffr::expect_doppelganger("z-curve KD2", function()plot(fit.KD2))
+ vdiffr::expect_doppelganger("z-curve KD2 (ggplot)", plot(fit.KD2, plot_type = "ggplot"))
})
test_that("z-curve EM censoring works", {
@@ -132,8 +134,8 @@ test_that("z-curve EM censoring works", {
))
# plot
- expect_doppelganger("z-curve mixed EM", function()plot(fit.mixed, CI = TRUE))
- expect_doppelganger("z-curve mixed EM (ggplot)", plot(fit.mixed, CI = TRUE, plot_type = "ggplot"))
+ vdiffr::expect_doppelganger("z-curve mixed EM", function()plot(fit.mixed, CI = TRUE))
+ vdiffr::expect_doppelganger("z-curve mixed EM (ggplot)", plot(fit.mixed, CI = TRUE, plot_type = "ggplot"))
# censoring only
@@ -157,8 +159,8 @@ test_that("z-curve EM censoring works", {
))
# plot
- expect_doppelganger("z-curve cens EM", function()plot(fit.cens, CI = TRUE))
- expect_doppelganger("z-curve cens EM (ggplot)", plot(fit.cens, CI = TRUE, plot_type = "ggplot"))
+ vdiffr::expect_doppelganger("z-curve cens EM", function()plot(fit.cens, CI = TRUE))
+ vdiffr::expect_doppelganger("z-curve cens EM (ggplot)", plot(fit.cens, CI = TRUE, plot_type = "ggplot"))
})
test_that("z-curve clustered works", {
@@ -204,7 +206,7 @@ test_that("z-curve clustered works", {
"Q = -238.11, 95% CI[-269.95, -219.12]"
))
- expect_doppelganger("z-curve clustered rounded", function(){
+ vdiffr::expect_doppelganger("z-curve clustered rounded", function(){
oldpar <- graphics::par(no.readonly = TRUE)
on.exit(graphics::par(mfrow = oldpar[["mfrow"]]))
par(mfrow = c(1, 2))
@@ -251,7 +253,7 @@ test_that("z-curve clustered works", {
"Q = -201.69, 95% CI[-219.18, -185.82]"
))
- expect_doppelganger("z-curve clustered precise", function(){
+ vdiffr::expect_doppelganger("z-curve clustered precise", function(){
oldpar <- graphics::par(no.readonly = TRUE)
on.exit(graphics::par(mfrow = oldpar[["mfrow"]]))
par(mfrow = c(1, 2))
@@ -298,7 +300,7 @@ test_that("z-curve clustered works", {
"Q = -321.39, 95% CI[-361.78, -298.20]"
))
- expect_doppelganger("z-curve clustered mixed", function(){
+ vdiffr::expect_doppelganger("z-curve clustered mixed", function(){
oldpar <- graphics::par(no.readonly = TRUE)
on.exit(graphics::par(mfrow = oldpar[["mfrow"]]))
par(mfrow = c(1, 2))
@@ -306,6 +308,6 @@ test_that("z-curve clustered works", {
plot(fitw)
})
- expect_doppelganger("z-curve clustered mixed (ggplot-1)", plot(fitb, plot_type = "ggplot"))
- expect_doppelganger("z-curve clustered mixed (ggplot-2)", plot(fitw, plot_type = "ggplot"))
+ vdiffr::expect_doppelganger("z-curve clustered mixed (ggplot-1)", plot(fitb, plot_type = "ggplot"))
+ vdiffr::expect_doppelganger("z-curve clustered mixed (ggplot-2)", plot(fitw, plot_type = "ggplot"))
})
\ No newline at end of file