From e43ac2dce88de43f5d8e26187bcb2e134af35742 Mon Sep 17 00:00:00 2001 From: rosieluain Date: Mon, 22 Jan 2024 19:44:42 -0700 Subject: [PATCH] code coverage --- .Rbuildignore | 1 + .github/workflows/test-coverage.yaml | 55 ++++++++++++++++++++++++++++ DESCRIPTION | 1 + R/mort.R | 28 +++++++++++++- README.Rmd | 1 + README.md | 3 ++ codecov.yml | 14 +++++++ 7 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 codecov.yml diff --git a/.Rbuildignore b/.Rbuildignore index 9078b1a..a6f7c68 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,4 @@ ^cran-comments\.md$ ^doc$ ^Meta$ +^codecov\.yml$ diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..729d01a --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,55 @@ +# 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 + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v3 + + - 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 + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + shell: Rscript {0} + + - 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@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/DESCRIPTION b/DESCRIPTION index b69fd89..7ad1cae 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,6 +21,7 @@ Imports: methods, rlang Suggests: + covr, ggplot2, knitr, plotly, diff --git a/R/mort.R b/R/mort.R index 78fc616..e345094 100644 --- a/R/mort.R +++ b/R/mort.R @@ -148,6 +148,11 @@ morts<-function(data,type="mort",ID,station,res.start="auto",res.end="auto", } } + # Check that all records have a station assigned + if (nrow(data[is.na(data[[station]]),])>0){ + stop("Station must be specified for all records.") + } + data.full<-data if (!is.null(season.start)| !is.null(season.end)){ @@ -680,6 +685,11 @@ infrequent<-function(data,type="mort",ID,station,res.start="auto", } } + # Check that all records have a station assigned + if (nrow(data[is.na(data[[station]]),])>0){ + stop("Station must be specified for all records.") + } + if (any(data[[station]]=="Break")){ warning("Either a station name was 'Break' or data included seasonal breaks. Breaks were removed.") @@ -764,7 +774,23 @@ infrequent<-function(data,type="mort",ID,station,res.start="auto", res.temp[[res.end]], units=recent.units)<=recent.period)) res.temp<-res.temp[j:nrow(res.temp),] - if (is.null(ddd)){ + if (nrow(res.temp)>0&length(unique(res.temp$Station.Name))==1){ + if (sum(res.temp[[residences]])=1& length(unique(res.temp[[station]]))==1& sum(res.temp[[residences]]) +[![Codecov test coverage](https://codecov.io/gh/rosieluain/mort/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rosieluain/mort?branch=main) The goal of mort is to provide a framework to identify potential mortalities or expelled tags in passive acoustic telemetry arrays with non-overlapping receivers. The potential mortalities that are flagged by mort should be reviewed by the user, and considered for removal from the dataset. diff --git a/README.md b/README.md index 7567244..ddeaf2c 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ # mort + +[![Codecov test +coverage](https://codecov.io/gh/rosieluain/mort/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rosieluain/mort?branch=main) The goal of mort is to provide a framework to identify potential diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true