Skip to content

Commit ba61c4d

Browse files
Merge pull request #22 from alaska-groundfish-efh/dev
Update for terra dependencies, fix bugs
2 parents 3f12260 + 3ebaea6 commit ba61c4d

33 files changed

+324
-217
lines changed

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
^\.Rproj\.user$
33
^dev$
44
^R/Meatgrinder5\.R$
5+
^LICENSE\.md$
6+
^doc$
7+
^Meta$

.github/workflows/r-cmd-check.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# R-CMD-Check
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
schedule:
9+
- cron: "0 0 1 * *"
10+
11+
name: r-cmd-check
12+
13+
jobs:
14+
15+
R-CMD-check:
16+
runs-on: ${{ matrix.config.os }}
17+
18+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
config:
24+
- {os: windows-latest, r: 'release'}
25+
- {os: macOS-latest, r: 'release'}
26+
27+
env:
28+
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
29+
RSPM: ${{ matrix.config.rspm }}
30+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
31+
R_KEEP_PKG_SOURCE: yes
32+
33+
steps:
34+
35+
- uses: actions/checkout@v4
36+
37+
- uses: r-lib/actions/setup-r@v2
38+
with:
39+
r-version: ${{ matrix.config.r }}
40+
41+
- uses: r-lib/actions/setup-pandoc@v2
42+
43+
- name: Query dependencies
44+
run: |
45+
install.packages('remotes')
46+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
47+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
48+
shell: Rscript {0}
49+
50+
- name: Cache R packages
51+
if: runner.os != 'Windows'
52+
uses: actions/cache@v2
53+
with:
54+
path: ${{ env.R_LIBS_USER }}
55+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
56+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
57+
58+
- name: Install dependencies
59+
run: |
60+
remotes::install_deps(dependencies = TRUE)
61+
remotes::install_cran("rcmdcheck")
62+
shell: Rscript {0}
63+
64+
- name: Check
65+
env:
66+
_R_CHECK_CRAN_INCOMING_REMOTE_: false
67+
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check")
68+
shell: Rscript {0}
69+
70+
- name: Show testthat output
71+
if: always()
72+
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
73+
shell: bash
74+
75+
- name: Upload check results
76+
if: failure()
77+
uses: actions/upload-artifact@main
78+
with:
79+
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
80+
path: check

.github/workflows/secretScan.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: gitleaks
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
gitleaks:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
with:
11+
fetch-depth: '0'
12+
- name: gitleaks-action
13+
uses: gitleaks/gitleaks-action@v1.6.0

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ vignettes/*.pdf
4242
*.html
4343
.Rproj.user
4444
inst/doc
45+
/doc/
46+
/Meta/

DESCRIPTION

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,32 @@ Authors@R:
1414
comment = c(ORCID = "0000-0002-4260-9856"))
1515
)
1616
Description: This package fits species distribution models (SDMs) to groundfish and crab data from the Eastern Bering Sea, Aleutian Islands, and Gulf of Alaska. These SDMs were used in the 2022 EFH 5-Year Review.
17-
License: `use_mit_license()`
17+
License: MIT + file LICENSE
1818
Encoding: UTF-8
1919
Roxygen: list(markdown = TRUE)
20-
RoxygenNote: 7.1.2
20+
RoxygenNote: 7.3.2
2121
Suggests:
2222
knitr,
2323
rmarkdown,
24+
gridExtra
2425
VignetteBuilder: knitr
2526
Imports:
2627
ggplot2,
27-
akgfmaps (>= 1.7.4),
28+
akgfmaps,
2829
viridis,
2930
stars,
3031
sf,
31-
gridExtra,
32-
patchwork,
33-
MASS,
3432
scales,
35-
labeling,
3633
mgcv,
3734
raster,
3835
PresenceAbsence,
39-
gstat,
4036
maxnet,
41-
ENMeval,
4237
xtable,
43-
XML,
4438
magrittr,
4539
terra,
4640
tidyterra
47-
Remotes:
48-
git::https://github.com/afsc-gap-products/akgfmaps.git@master
41+
Remotes: afsc-gap-products/akgfmaps
4942
Depends:
5043
R (>= 3.5.0)
5144
LazyData:
52-
true
45+
false

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YEAR: 2024
2+
COPYRIGHT HOLDER: EFHSDM authors

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2024 EFHSDM authors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ export(RMSE)
3333
export(ValidateEnsemble)
3434
importFrom(akgfmaps,get_base_layers)
3535
importFrom(magrittr,"%>%")
36+
importFrom(stats,aggregate)
37+
importFrom(stats,density)
38+
importFrom(stats,var)
39+
importFrom(terra,classify)
40+
importFrom(terra,extract)
41+
importFrom(terra,setValues)
42+
importFrom(terra,values)

R/Functions_Ensemble.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ GetEnsembleVariance<-function(model.weights,variance.list,abund.list,ensemble.ab
266266
#' @param model.weights vector of numeric weights for each model, must match order of effects.list
267267
#' @param vars character; vector of desired term names or "all"
268268
#' @param scale character; should effects be in "log" or "abund" scale
269+
#' @importFrom stats var
269270
#'
270271
#' @return list of data frames containing the estimated covariate effects in the ensemble
271272
#' @export

R/Functions_GamModel.R

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
# This script includes functions for fitting GAM and HGAM models
2-
3-
# Setting lists of required packages & installing it
4-
# rpackages <- c("mgcv", "raster", "PresenceAbsence")
5-
#
6-
# # rJava, rgeos, maps
7-
# which_not_installed <- which(rpackages %in% rownames(installed.packages()) == FALSE)
8-
#
9-
# if (length(which_not_installed) > 1) {
10-
# install.packages(rpackages[which_not_installed], dep = TRUE)
11-
# }
12-
# rm(rpackages, which_not_installed)
13-
#
14-
# require(mgcv)
15-
# require(raster)
16-
# require(PresenceAbsence)
17-
18-
191
#' Make a GAM formula
202
#'
213
#' @description Improved version designed to use the tables produced by the Autodetect functions
@@ -27,7 +9,6 @@
279
#' @return Returns a formula object, or list of formulas for hgam
2810
#' @export
2911
#'
30-
#'
3112
#' @examples
3213
AssembleGAMFormula <- function(yvar, gam.table, hgam = F) {
3314

@@ -123,6 +104,13 @@ AssembleGAMFormula <- function(yvar, gam.table, hgam = F) {
123104
#' @export
124105
#'
125106
#' @examples
107+
#' gam.form <- formula("a_atf ~ s(lon,lat,bs = 'ds',m=c(1,.5), k=10) + s(bdepth, bs='tp',m=1,k=4) + s(btemp, bs='tp',m=1,k=4) + s(slope, bs='tp',m=1,k=4) + offset(logarea)")
108+
#' data("region_data_all")
109+
#' region_data_all$sponge <- as.integer(region_data_all$sponge > 0)
110+
#' region_data_all$logarea <- log(region_data_all$area)
111+
#'
112+
#' poisson.model <- FitGAM(gam.formula = gam.form, data = region_data_all, family.gam = "poisson")
113+
126114
FitGAM <- function(data,
127115
gam.formula = NULL,
128116
reduce = F,
@@ -496,7 +484,7 @@ AutodetectGAMTerms <- function(model, hgam = "all") {
496484
#' @param model a GAM model object
497485
#' @param data a data frame; usually the same one used to fit the GAM model
498486
#'
499-
#' @return a named vector of decimal values indicating the percent contribution
487+
#' @return a named vector of decimal values indicating the percent contribution to deviance explained
500488
#' @export
501489
#'
502490
#' @examples
@@ -560,7 +548,7 @@ GAMStats <- function(model, # a gam model
560548
# update progress bar
561549
utils::setTxtProgressBar(pb, i)
562550
} else {
563-
utils::setTxtProgressBar(pb, length(gam.terms))
551+
utils::setTxtProgressBar(pb, length(gam.terms)) # maybe change this to just 'terms'?
564552
print("Deviance could not be estimated for model; returning NAs")
565553
break
566554
}

0 commit comments

Comments
 (0)