Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: serocalculator
Title: Estimating Infection Rates from Serological Data
Version: 1.3.0.9059
Version: 1.3.0.9060
Authors@R: c(
person("Peter", "Teunis", , "p.teunis@emory.edu", role = c("aut", "cph"),
comment = "Author of the method and original code."),
Expand Down Expand Up @@ -76,4 +76,5 @@ Language: en-US
LazyData: true
NeedsCompilation: no
Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace", "devtag::dev_roclet"))
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
Config/Needs/build: moodymudskipper/devtag
Comment thread
kristinawlai marked this conversation as resolved.
Outdated
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export(est.incidence)
export(est.incidence.by)
export(est_seroincidence)
export(est_seroincidence_by)
export(expect_snapshot_data)
export(f_dev)
export(f_dev0)
export(fdev)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ would get merged by `ggplot2::aes(group = iter)` (#382)

## Internal changes

* switched `expect_snapshot_data()` to an internal function due to CRAN errors (#464)
* generalized `ab1()`
* added codecov/test-results-action to test-coverage.yaml workflow
* added test for censored data in f_dev() (#399)
Expand Down
2 changes: 1 addition & 1 deletion R/check_strata.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' sees_pop_data_pk_100 |>
#' check_strata(strata = c("ag", "catch", "Count")) |>
#' try()
#' @dev

Comment thread
kristinawlai marked this conversation as resolved.
Outdated
check_strata <- function(pop_data,
strata,
biomarker_names_var =
Expand Down
35 changes: 35 additions & 0 deletions R/expect_snapshot_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' Snapshot testing for [data.frame]s
#' @description
#' copied from <https://github.com/bcgov/ssdtools>
#' with permission (<https://github.com/bcgov/ssdtools/issues/379>)
#'
#' @param x a [data.frame] to snapshot
#' @param name [character] snapshot name
#' @param digits [integer] passed to [signif()] for numeric variables
#'
#' @returns [NULL] (from [testthat::expect_snapshot_file()])
#' @export
#' @keywords internal
#' @examples
#' \donttest{
#' expect_snapshot_data(iris, name = "iris")
#' }
expect_snapshot_data <- function(x, name, digits = 6) {
fun <- function(x) signif(x, digits = digits)
lapply_fun <- function(x) I(lapply(x, fun))
x <- dplyr::mutate(x, dplyr::across(tidyselect::where(is.numeric), fun))
x <- dplyr::mutate(x, dplyr::across(tidyselect::where(is.list), lapply_fun))
path <- save_csv(x)
testthat::expect_snapshot_file(
path,
paste0(name, ".csv"),
compare = testthat::compare_file_text
)
}


save_csv <- function(x) {
path <- tempfile(fileext = ".csv")
readr::write_csv(x, path)
path
}
1 change: 0 additions & 1 deletion man/check_strata.Rd

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

28 changes: 28 additions & 0 deletions man/expect_snapshot_data.Rd

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

14 changes: 11 additions & 3 deletions man/plot_curve_params_one_ab.Rd

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/autoplot.pop_data/density-log.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/autoplot.pop_data/density.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testthat/_snaps/graph.curve.params/curve-samples.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 25 additions & 25 deletions tests/testthat/test-ab.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
test_that("`ab()` works consistently", {

par1 <- matrix(
c(
1.11418923843475, 1, 0.12415057798022207, 0.24829344792968783,
0.01998946878312856, 0.0012360802436587237, 1.297194045996013,
1.3976510415108334, 1, 0.2159993563893431, 0.4318070551383313,
0.0015146395107173347, 0.0003580062906750277, 1.5695811573082081
),
nrow = 7L,
ncol = 2L,
dimnames = list(
params = c("y0", "b0", "mu0", "mu1", "c1", "alpha", "shape_r"),
antigen_iso = c("HlyE_IgA", "HlyE_IgG")
)
)
t <- 0:1444
blims <- matrix(
rep(c(0, 0.5), each = 2L),
nrow = 2L,
ncol = 2L,
dimnames = list(c("HlyE_IgA", "HlyE_IgG"), c("min", "max"))
)
preds <- ab(t = t, par = par1, blims = blims)
par1 <- matrix(
c(
1.11418923843475, 1, 0.12415057798022207, 0.24829344792968783,
0.01998946878312856, 0.0012360802436587237, 1.297194045996013,
1.3976510415108334, 1, 0.2159993563893431, 0.4318070551383313,
0.0015146395107173347, 0.0003580062906750277, 1.5695811573082081
),
nrow = 7L,
ncol = 2L,
dimnames = list(
params = c("y0", "b0", "mu0", "mu1", "c1", "alpha", "shape_r"),
antigen_iso = c("HlyE_IgA", "HlyE_IgG")
)
)
t <- 0:1444
blims <- matrix(
rep(c(0, 0.5), each = 2L),
nrow = 2L,
ncol = 2L,
dimnames = list(c("HlyE_IgA", "HlyE_IgG"), c("min", "max"))
)
preds <- ab(t = t, par = par1, blims = blims)

colnames(preds) <- colnames(par1)
colnames(preds) <- colnames(par1)

preds2 <- preds |> as_tibble()
preds2 <- preds |> as_tibble()

ssdtools:::expect_snapshot_data(preds2, name = "ab-preds")
expect_snapshot_data(preds2, name = "ab-preds")

})
2 changes: 1 addition & 1 deletion tests/testthat/test-analyze_sims.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that(

test_sim_results |>
analyze_sims() |>
ssdtools:::expect_snapshot_data(name = "sim_results")
expect_snapshot_data(name = "sim_results")

}
)
2 changes: 1 addition & 1 deletion tests/testthat/test-as_sr_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_that("`as_sr_params()` produces expected results", {

expect_snapshot_value(x = test_data, style = "serialize")

test_data |> ssdtools:::expect_snapshot_data(name = "curve-data")
test_data |> expect_snapshot_data(name = "curve-data")


})
2 changes: 1 addition & 1 deletion tests/testthat/test-sim_pop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ test_that("`sim_pop_data()` produces consistent results", {
format = "long"
)

ssdtools:::expect_snapshot_data(csdata, "sim_pop_data")
expect_snapshot_data(csdata, name = "sim_pop_data")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-sim_pop_data_multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Simulated incidence rate per person-year
lambdas <- c(.05, .1, .15, .2, .3)
# lambdas <- c(.05)

Check warning on line 14 in tests/testthat/test-sim_pop_data_multi.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=tests/testthat/test-sim_pop_data_multi.R,line=14,col=5,[commented_code_linter] Remove commented code.
# Range covered in simulations
lifespan <- c(0, 10)

Expand Down Expand Up @@ -39,5 +39,5 @@
)

pop_data_multi |>
ssdtools:::expect_snapshot_data(name = "pop_data_multi")
expect_snapshot_data(name = "pop_data_multi")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-strata.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("results are consistent", {

sees_typhoid_ests_strat |>
strata() |>
ssdtools:::expect_snapshot_data(name = "strata-ests")
expect_snapshot_data(name = "strata-ests")


})
Loading