Skip to content

Commit 54ff44d

Browse files
committed
update data, add basic tests
Data updated through Nov 2023
1 parent 8c66668 commit 54ff44d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+915
-1345
lines changed

.github/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/R-CMD-check.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
name: R-CMD-check
10+
11+
jobs:
12+
R-CMD-check:
13+
runs-on: ${{ matrix.config.os }}
14+
15+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
config:
21+
- {os: macOS-latest, r: 'release'}
22+
- {os: windows-latest, r: 'release'}
23+
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
24+
- {os: ubuntu-latest, r: 'release'}
25+
- {os: ubuntu-latest, r: 'oldrel-1'}
26+
27+
env:
28+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
29+
R_KEEP_PKG_SOURCE: yes
30+
31+
steps:
32+
- uses: actions/checkout@v2
33+
34+
- uses: r-lib/actions/setup-pandoc@v2
35+
36+
- uses: r-lib/actions/setup-r@v2
37+
with:
38+
r-version: ${{ matrix.config.r }}
39+
http-user-agent: ${{ matrix.config.http-user-agent }}
40+
use-public-rspm: true
41+
42+
- uses: r-lib/actions/setup-r-dependencies@v2
43+
with:
44+
extra-packages: rcmdcheck
45+
46+
- uses: r-lib/actions/check-r-package@v2
47+
48+
- name: Show testthat output
49+
if: always()
50+
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
51+
shell: bash
52+
53+
- name: Upload check results
54+
if: failure()
55+
uses: actions/upload-artifact@main
56+
with:
57+
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
58+
path: check

DESCRIPTION

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
Package: kwdemog
22
Type: Package
33
Title: Package for processing and exploring killer whale demographic data
4-
Version: 1.0.2
5-
Date: 2021-12-12
4+
Version: 1.0.3
5+
Date: 2023-12-15
66
Authors@R: c(
77
person(c("Eric", "J."), "Ward", email = "eric.ward@noaa.gov",
88
role = c("aut", "cre")))
99
Description: Generates killer whale demographic data from rows (observations) and fits preliminary models.
1010
Depends:
1111
R (>= 4.0.0)
12-
Imports: dplyr,ggplot2,mgcv,usethis,rstanarm,stringr,viridis,ggridges
12+
Imports: dplyr,mgcv,usethis,stringr,ggridges,ggplot2,rstanarm,viridis
1313
Suggests: knitr,
1414
rmarkdown,
1515
gridExtra
16+
URL: https://noaa-nwfsc.github.io/srkw-status/
17+
BugReports: https://github.com/noaa-nwfsc/srkw-status/issues
1618
License: GPL (>=3)
17-
RoxygenNote: 7.1.2
19+
RoxygenNote: 7.2.3
1820
Encoding: UTF-8
1921
VignetteBuilder: knitr
2022
LazyData: true

LICENSE

Lines changed: 0 additions & 674 deletions
This file was deleted.

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export(project)
55
export(writedata)
66
import(dplyr)
77
import(mgcv)
8+
importFrom(stats,rbeta)
89
importFrom(stats,rnorm)
910
importFrom(stats,runif)
1011
importFrom(stringr,str_locate)

R/expand.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ expand <- function(filename, start_year = 1976, current_year = NULL,
2424
fem_age_mat = 10, fem_age_senesc = 43, ages2stages = NULL) {
2525
if(is.null(current_year)) current_year = as.numeric(substr(Sys.Date(),1,4))
2626

27-
if(class(filename) == "data.frame") orca = filename
28-
if(class(filename) == "character") orca = read.csv(filename, stringsAsFactors = FALSE)
27+
if(inherits(filename, "data.frame")) orca = filename
28+
if(inherits(filename, "character")) orca = read.csv(filename, stringsAsFactors = FALSE)
2929
orca$population = ifelse(orca$pod %in% c("J001","K001","L001"), "SRKW", "NRKW")
3030
# create expanded data frame of all years and animals
3131
alldat = expand.grid("year" = start_year:current_year,

R/project.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
#' e.g. "1981:1985" to use rates from 1981 to 1985 or ("1981:1985","1981:2021")
1010
#' @param verbose whether to print status updates to screen, defaults to FALSE
1111
#' @param p_female The probability of a female birth, defaults to the empirical value since 1980
12-
#' @param n_births Used for uncertainty in the sex ratio at birth. The distribution of female births is
13-
#' assumed to be beta binomial, with shape parameters `(n_births+1)*p_female` and `(n_births+1)*(1-p_female)`.
14-
#' There have been approximately 100 births since 1980, and this defaults to the empirical number
15-
#' of births
16-
#' formula above
12+
#' @param n_births The number of births used to calculate `p_female`. By default, this defaults to the empirical
13+
#' value observed since 1980 the probability of female birth. Larger values result in more precise estimates of `p_female`
1714
#'
1815
#' @import dplyr
1916
#' @import mgcv
20-
#' @importFrom stats rnorm runif
17+
#' @importFrom stats rnorm runif rbeta
2118
#' @importFrom stringr str_locate
2219
#'
2320
#' @export
@@ -27,7 +24,7 @@ project = function(whale_data, seed = 123,
2724
n_iter = 200,
2825
verbose = FALSE,
2926
p_female = NA,
30-
sd_female = NA) {
27+
n_births = NA) {
3128
set.seed(seed)
3229

3330
data = whale_data
@@ -101,7 +98,8 @@ project = function(whale_data, seed = 123,
10198

10299
initPopCurrent$sex = as.numeric(initPopCurrent$sex)
103100
# assign sexes to unsexed individuals [0s]
104-
initPopCurrent$sex[which(initPopCurrent$Sex==0)] = ifelse(runif(length(which(initPopCurrent$sex==0))) < rnorm(length(which(initPopCurrent$sex==0)),p_female, sd_female), 1, 2)
101+
initPopCurrent$sex[which(initPopCurrent$Sex==0)] = ifelse(runif(length(which(initPopCurrent$sex==0))) < rbeta(length(which(initPopCurrent$sex==0)), beta_1, beta_2), 1, 2)
102+
#initPopCurrent$sex[which(initPopCurrent$Sex==0)] = ifelse(runif(length(which(initPopCurrent$sex==0))) < rnorm(length(which(initPopCurrent$sex==0)),p_female, sd_female), 1, 2)
105103
newID = 9999
106104

107105
for(yrs in 1:dim(popSize)[2]) {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 'kwdemog' package
22

3-
This is a repository (pkgdown site here: https://nwfsc-cb.github.io/srkw-status/) for archiving code and data related to projecting Southern Resident killer whale population status. The data are included as an .rda file in the /data folder. In addition to using this framework for population projections this has been used extensively for the Pacific Fishery Management Council Working Group to understand the effects of ocean salmon fisheries on killer whales.
3+
This is a repository (pkgdown site here: https://noaa-nwfsc.github.io/srkw-status/) for archiving code and data related to projecting Southern Resident killer whale population status. The data are included as an .rda file in the /data folder. In addition to using this framework for population projections this has been used extensively for the Pacific Fishery Management Council Working Group to understand the effects of ocean salmon fisheries on killer whales.
44

55
[2020 PFMC Risk Assessment](https://www.pcouncil.org/documents/2020/02/e-3-a-srkw-workgroup-report-1-electronic-only.pdf/)
66

data/orca.rda

56 Bytes
Binary file not shown.

data/projections.rda

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)