Skip to content

Commit

Permalink
Merge pull request #82 from NOAA-EDAB/UnitTests
Browse files Browse the repository at this point in the history
Unit tests
  • Loading branch information
rklasky authored Apr 12, 2024
2 parents 57ec69e + 8cf3e3d commit 17bb8cd
Show file tree
Hide file tree
Showing 116 changed files with 4,044 additions and 593 deletions.
13 changes: 13 additions & 0 deletions ..Rcheck/00check.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
* using log directory ‘/home/rklasky/R/packages/Rpath/..Rcheck’
* using R version 4.3.1 (2023-06-16)
* using platform: x86_64-pc-linux-gnu (64-bit)
* R was compiled by
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
GNU Fortran (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
* running under: Linux Mint 20
* using session charset: UTF-8
* checking for file ‘./DESCRIPTION’ ... ERROR
Required fields missing or empty:
‘Author’ ‘Maintainer’
* DONE
Status: 1 ERROR
18 changes: 10 additions & 8 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^_pkgdown\.yml$
^docs$
^pkgdown$
^data-raw$

^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^_pkgdown\.yml$
^docs$
^pkgdown$
^data-raw$
^doc$
^Meta$
1 change: 1 addition & 0 deletions .Renviron
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_R_CHECK_DONTTEST_EXAMPLES_=FALSE
31 changes: 11 additions & 20 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 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]
branches: [main, master, UnitTests]
pull_request:
branches: [main, master]

Expand All @@ -18,7 +18,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,30 +29,21 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- 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@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck

- uses: r-lib/actions/check-r-package@v1

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
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
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@master

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/secretScan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
fetch-depth: '2'
- name: gitleaks-action
uses: zricethezav/gitleaks-action@master
uses: gitleaks/gitleaks-action@v1.6.0
94 changes: 94 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

on:
push:
paths:
- '.github/workflows/tests.yml'
- 'R/*'
- 'tests/testthat/*'
- 'README.md'
- 'DESCRIPTION'
pull_request:
paths:
- '.github/workflows/tests.yml'
- 'R/*'
- 'tests/testthat/*'

name: Unit-Tests

jobs:
# build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: r-lib/actions/setup-r@v2
# - uses: r-lib/actions/setup-pandoc@v2
# - name: Install dependencies
# run: Rscript -e "install.packages(c('testthat', 'tidyverse', 'here'))"
# - name: Run tests
# run: Rscript -e "source('tests/testthat.R')"

Unit-Tests:
runs-on: ${{matrix.config.os}}

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

strategy:
fail-fast: false
matrix:
#os: [macos-latest, ubuntu-latest, windows-latest]
#os: [ubuntu-latest]
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
# R_REMOTES_NO_ERRORS_FROM_WARNINGS: false
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4
# with:
# fetch-depth: 0

- 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
# r-version: '4.3.1'

- uses: r-lib/actions/setup-r-dependencies@v2

- name: Install command line packages
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt-get install libcurl4-openssl-dev libgit2-dev
- name: Install dependencies
#run: Rscript -e "install.packages(c('remotes','testthat', 'tidyverse', 'here'))"
run: |
install.packages(c('usethis','remotes','testthat','tidyverse','here','rmarkdown','qpdf','distillery','ggpubr','rlist'))
remotes::install_github("NOAA-EDAB/Rpath")
shell: Rscript {0}

- name: Run tests
#run: Rscript -e "source('tests/testthat.R')"
run: |
source(here::here("data-raw/REcosystem.R"))
source(here::here("tests/testthat.R"))
shell: Rscript {0}

# - name: commit data files
# run: |
# git config user.name github-actions
# git config user.email [email protected]
# file.copy('here::here("tests/testthat/Rplots.pdf")",to=here::here("inst/extdata/Rplots.pdf"))
# git add inst/extdata/Rplots.pdf
# git commit -m "automated commit from testthat yml"
# git push
17 changes: 14 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
.Rproj.user
.Rhistory
.RData
*.png
.Renviron
*.jpg
*.tif
*.tar
*.so
outputs
code
*.xlsx
*.docx
*.pdf
Ecopath_dev
Rpath.Rcheck*
src/*.o
src/*.dll
NAMESPACE
tests/testthat/data/output/*
tests/testthat/data/bkup/*
tests/testthat/data/input/REcosystem_Current_*.dat
tests/testthat/data/input/REcosystem_Current_*.csv
tests/testthat/old/*
tests/testthat/bkup/*
tests/testthat/old dat files/*
docs
Rpath.Rproj
doc
Meta
Rpath.Rproj
82 changes: 48 additions & 34 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
Package: Rpath
Type: Package
Title: R implementation of Ecopath with Ecosim
Version: 0.0.1.2
Date: 2016-07-15
Authors@R: c(
person("Kerim", "Aydin", email = "[email protected]", role = "aut"),
person("Sean", "Lucey", email = "[email protected]",
role = c("aut", "cre")),
person("Sarah", "Gaichas", email = "[email protected]", role = "aut"))
Description: This package implements the core mass balance equations made popular
by Ecopath with Ecosim. There are two parts to the package, the static snapshot
of energy flow through the system using rpath and dynamic simulations run using
the rsim family of functions.
License: file LICENSE
Encoding: UTF-8
Imports:
data.table,
graphics,
grDevices,
MASS,
Rcpp (>= 0.11.3),
stats,
utils
LinkingTo: Rcpp
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
RoxygenNote: 7.1.1
URL: https://github.com/NOAA-EDAB/Rpath
BugReports: https://github.com/NOAA-EDAB/Rpath/issues
Depends:
R (>= 2.10)
Package: Rpath
Type: Package
Title: R implementation of Ecopath with Ecosim
Version: 0.0.1.2
Date: 2016-07-15
Authors@R: c(
person("Kerim", "Aydin", email = "[email protected]", role = "aut"),
person("Sean", "Lucey", email = "[email protected]",
role = c("aut", "cre")),
person("Sarah", "Gaichas", email = "[email protected]", role = "aut"))
Description: This package implements the core mass balance equations made popular
by Ecopath with Ecosim. There are two parts to the package, the static snapshot
of energy flow through the system using rpath and dynamic simulations run using
the rsim family of functions.
License: file LICENSE
Encoding: UTF-8
Imports:
data.table,
methods,
graphics,
grDevices,
MASS,
Rcpp (>= 0.11.3),
stats,
utils
LinkingTo: Rcpp
Suggests:
here,
knitr,
rmarkdown,
distillery,
ggplot2,
ggpubr,
rlist,
stringr,
qpdf,
usethis,
dplyr,
generics,
testthat (>= 3.0.0)
VignetteBuilder: knitr
RoxygenNote: 7.2.3
URL: https://github.com/NOAA-EDAB/Rpath
BugReports: https://github.com/NOAA-EDAB/Rpath/issues
Depends:
R (>= 2.10)
Config/testthat/edition: 3
LazyData: true
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ import(stats)
import(utils)
importFrom(Rcpp,sourceCpp)
importFrom(grDevices,rainbow)
importFrom(methods,is)
useDynLib(Rpath)
46 changes: 23 additions & 23 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

rk4_run <- function(params, instate, forcing, fishing, stanzas, StartYear, EndYear) {
.Call('_Rpath_rk4_run', PACKAGE = 'Rpath', params, instate, forcing, fishing, stanzas, StartYear, EndYear)
}

Adams_run <- function(params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv) {
.Call('_Rpath_Adams_run', PACKAGE = 'Rpath', params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv)
}

deriv_vector <- function(params, state, forcing, fishing, stanzas, inyear, m, tt) {
.Call('_Rpath_deriv_vector', PACKAGE = 'Rpath', params, state, forcing, fishing, stanzas, inyear, m, tt)
}

SplitSetPred <- function(stanzas, state) {
.Call('_Rpath_SplitSetPred', PACKAGE = 'Rpath', stanzas, state)
}

SplitUpdate <- function(stanzas, state, forcing, deriv, yr, mon) {
.Call('_Rpath_SplitUpdate', PACKAGE = 'Rpath', stanzas, state, forcing, deriv, yr, mon)
}

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

rk4_run <- function(params, instate, forcing, fishing, stanzas, StartYear, EndYear) {
.Call('_Rpath_rk4_run', PACKAGE = 'Rpath', params, instate, forcing, fishing, stanzas, StartYear, EndYear)
}

Adams_run <- function(params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv) {
.Call('_Rpath_Adams_run', PACKAGE = 'Rpath', params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv)
}

deriv_vector <- function(params, state, forcing, fishing, stanzas, inyear, m, tt) {
.Call('_Rpath_deriv_vector', PACKAGE = 'Rpath', params, state, forcing, fishing, stanzas, inyear, m, tt)
}

SplitSetPred <- function(stanzas, state) {
.Call('_Rpath_SplitSetPred', PACKAGE = 'Rpath', stanzas, state)
}

SplitUpdate <- function(stanzas, state, forcing, deriv, yr, mon) {
.Call('_Rpath_SplitUpdate', PACKAGE = 'Rpath', stanzas, state, forcing, deriv, yr, mon)
}

14 changes: 10 additions & 4 deletions R/Rpath_support.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
library(methods)

########################################################################################
# Set of functions for returning functional group names (character vector)
# using the type input column
#
# Internal supporting function for group names to check type
grouptype <- function(Rpath){
if(class(Rpath)=="Rpath"){gt<-list(type=Rpath$type, grp=Rpath$Group)}
else{
if(class(Rpath)=="Rpath.params"){
#'
#' @importFrom methods is
#'
grouptype <- function(Rpath) {
if (is(Rpath,"Rpath")) {
gt<-list(type=Rpath$type, grp=Rpath$Group)
} else {
if (is(Rpath,"Rpath.params")) {
gt<-list(type=Rpath$model$Type, grp=Rpath$model$Group)}
else{
stop("Input must be an Rpath (balanced) or Rpath.params (unbalanced) object.")
Expand Down
Loading

0 comments on commit 17bb8cd

Please sign in to comment.