Skip to content

Commit

Permalink
- Added gss() function from gsdd package to calculate growing sea…
Browse files Browse the repository at this point in the history
…sons.
  • Loading branch information
joethorley committed Apr 3, 2024
1 parent fa00525 commit f8c0b9c
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Depends:
Imports:
chk,
dplyr,
fishbc,
gsdd (>= 0.0.1),
fishbc (>= 0.2.1),
gsdd (>= 0.0.2),
lifecycle,
purrr,
rlang,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(freshwaterfish)
export(gdd)
export(gsdd)
export(gsdd_cf)
export(gss)
export(interpolate_numeric_vector)
import(chk)
importFrom(fishbc,fbc_common_name)
Expand Down
2 changes: 1 addition & 1 deletion R/gdd.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' the longest growing season.
#'
#' @inheritParams gsdd::gdd
#' @seealso [gsdd::gdd()] and [gsdd()].
#' @seealso [gsdd::gdd()], [gsdd()] and [gss()].
#' @export
#'
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/gsdd.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' the longest growing season.
#'
#' @inheritParams gsdd::gsdd
#' @seealso [gsdd::gsdd()], [gdd()] and [gsdd_vctr()].
#' @seealso [gsdd::gsdd()], [gsdd()] and [gss()].
#' @export
#'
#' @examples
Expand Down
29 changes: 29 additions & 0 deletions R/gss.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' Calculate Growing Seasons (GSS)
#'
#' A wrapper on [gsdd::gss()] to by default
#' get all Growing Seasons ignoring truncation.
#' For more information see [gsdd::gss()].
#'
#' @inheritParams gsdd::gdd
#' @seealso [gsdd::gss()], [gsdd()] and [gss()].
#' @export
#'
#' @examples
#' gss(gsdd::temperature_data)
gss <- function(
x,
min_length = 120,
ignore_truncation = TRUE,
pick = "all",
msgs = TRUE
) {
chk_whole_number(min_length)
chk_range(min_length, c(14, 274))

gsdd::gss(
x,
min_length = min_length,
ignore_truncation = ignore_truncation,
pick = pick,
msgs = msgs)
}
2 changes: 1 addition & 1 deletion man/gdd.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/gsdd.Rd

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

39 changes: 39 additions & 0 deletions man/gss.Rd

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

44 changes: 44 additions & 0 deletions tests/testthat/_snaps/gss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# gss works

Code
gss
Output
# A tibble: 1 x 5
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-03-20 1971-11-07 3899. none

# gss works t2

Code
gss
Output
# A tibble: 2 x 5
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-04-08 1971-06-04 500 none
2 2019 1971-07-15 1971-09-03 800 none

# gss truncation off

Code
gss
Output
# A tibble: 0 x 5
# i 5 variables: year <int>, start_dayte <date>, end_dayte <date>, gsdd <dbl>,
# truncation <chr>

# gss truncation on

Code
gss
Output
# A tibble: 2 x 5
# Groups: year [1]
year start_dayte end_dayte gsdd truncation
<int> <date> <date> <dbl> <chr>
1 2019 1971-04-08 1971-06-04 500 none
2 2019 1971-07-15 1971-11-30 1255 end

35 changes: 35 additions & 0 deletions tests/testthat/test-gss.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
test_that("gss works", {
gss <- gss(gsdd::temperature_data)
expect_snapshot({
gss
})
})

test_that("gss works t2", {
data <- gsdd::temperature_data
data$temperature <- data$temperature2
gss <- gss(data)
expect_snapshot({
gss
})
})

test_that("gss truncation off", {
data <- gsdd::temperature_data
data$temperature <- data$temperature2
data$temperature[data$date >= as.Date("2019-08-28")] <- 5
gss <- gss(data, ignore_truncation = FALSE, msgs = FALSE)
expect_snapshot({
gss
})
})

test_that("gss truncation on", {
data <- gsdd::temperature_data
data$temperature <- data$temperature2
data$temperature[data$date >= as.Date("2019-08-28")] <- 5
gss <- gss(data)
expect_snapshot({
gss
})
})

0 comments on commit f8c0b9c

Please sign in to comment.