Skip to content

Commit

Permalink
Harbour seals - add tests and update documentation, document(), #38.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-edwards committed Oct 24, 2023
1 parent 0e795fa commit 0806a87
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
4 changes: 3 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@
##' Report. 2022/034.
##' https://www.dfo-mpo.gc.ca/csas-sccs/Publications/SAR-AS/2022/2022_034-eng.html
##'
##' See also: `harbour_seals_data_final_year` for the year of the final data for
##' each region.
##' @format A tibble also of class `pacea_harbour_seals` with columns:
##' \describe{
##' \item{date:}{Date of the GAM estimate of abundance; there is a time step
Expand Down Expand Up @@ -1009,7 +1011,7 @@

##' Final year of Pacific Harbour Seals survey in each of seven regions
##'
##' Used for colouring the plots of the estimates contained in `harbour_seals`
##' Used for understanding the final year of data for the estimates contained in `harbour_seals`
##' (since some are projections beyond the data). Also see `?harbour_seals`.
##'
##' @format A tibble with columns:
Expand Down
5 changes: 1 addition & 4 deletions R/plot-pacea-harbour-seals.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
##' @param median_line_col col for median
##' @param median_line_lty lty for median
##' @param median_line_lwd lwd for median
##' @param ... further options passed onto `plot.default()`
##' @inherit plot.pacea_index
##' @return plot of the time series as median with bars showing uncertainty (if
##' `low` and `high` are columns of `obj) to the current device; returns nothing.
Expand Down Expand Up @@ -59,9 +58,7 @@ plot.pacea_harbour_seals <- function(obj,
median_pch = 16,
median_line_col = "black",
median_line_lty = 1,
median_line_lwd = 2,
... # pass onto default plot
){
median_line_lwd = 2){

stopifnot("value must be a column of the object in the first argument" =
value %in% names(obj))
Expand Down
3 changes: 3 additions & 0 deletions man/harbour_seals.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/harbour_seals_data_final_year.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions man/plot.pacea_harbour_seals.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion tests/testthat/test-plot-time-series.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# These are on plotting functions for pacea_index and then pacea_recruitment and pacea_biomass objects.
# These are on plotting functions for pacea_index and then pacea_recruitment,
# pacea_biomass, pacea_buoy, and pacea_harbour_seals objects.

test_that("index plotting: the stopifnot commands are working", {
expect_error(plot(oni,
Expand Down Expand Up @@ -91,3 +92,20 @@ test_that("buoy SST plotting works with various options", {
years = 2010:2020))
expect_error(plot(buoy_sst, stn_id = c("C46004", "C46036")))
})

# plot.pacea_harbour_seals()
test_that("harbour seals plotting works with various options", {
expect_visible(plot(harbour_seals))
expect_invisible(plot(harbour_seals,
region = "SOG"))
expect_error(plot(harbour_seals,
region = "nonsense"))
expect_error(plot(harbour_seals,
value = "nonsense"))
# Doesn't pass, even though figures do look the same
#expect_equal(plot(dplyr::filter(harbour_seals,
# region != "Coastwide")),
# plot(harbour_seals,
# include_coastwide = FALSE))

})

0 comments on commit 0806a87

Please sign in to comment.