Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore sim.cs() and sim.cs.multi() to the export list #373

Merged
merged 5 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ README_files
NEWS.html
NEWS_files
**/.quarto/
*.pdf
2 changes: 1 addition & 1 deletion 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.9019
Version: 1.3.0.9020
Authors@R: c(
person("Peter", "Teunis", , "[email protected]", role = c("aut", "cph"),
comment = "Author of the method and original code."),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export(load_noise_params)
export(load_pop_data)
export(log_likelihood)
export(serocalculator_example)
export(sim.cs)
export(sim.cs.multi)
export(sim_pop_data)
export(sim_pop_data_multi)
export(strata)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Extended `simulate_xsectionalData.Rmd` article to explore
`renew_params = TRUE` vs `renew_params = FALSE` (#348)

* Renamed variables for consistency (#281):
* Renamed variables for consistency (#281, #373):
- `sim.cs()` -> `sim_pop_data()`
- `sim.cs.multi()` -> `sim_pop_data_multi()`

Expand Down
43 changes: 22 additions & 21 deletions R/sim_pop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
...) {
if (verbose > 1) {
message("inputs to `sim_pop_data()`:")
print(environment() %>% as.list())
print(environment() |> as.list())

Check warning on line 96 in R/sim_pop_data.R

View check run for this annotation

Codecov / codecov/patch

R/sim_pop_data.R#L96

Added line #L96 was not covered by tests
}


Expand All @@ -105,18 +105,18 @@
# and provide `curve_params` instead.

predpar <-
curve_params %>%
filter(.data$antigen_iso %in% antigen_isos) %>%
droplevels() %>%
prep_curve_params_for_array() %>%
curve_params |>
filter(.data$antigen_iso %in% antigen_isos) |>
droplevels() |>
prep_curve_params_for_array() |>
df_to_array(dim_var_names = c("antigen_iso", "parameter"))

stopifnot(length(lambda) == 1)

day2yr <- 365.25
lambda <- lambda / day2yr
age_range <- age_range * day2yr
npar <- dimnames(predpar)$parameter %>% length()
npar <- dimnames(predpar)$parameter |> length()


baseline_limits <- noise_limits
Expand Down Expand Up @@ -149,8 +149,8 @@
colnames(ysim) <- c("age", antigen_isos)

to_return <-
ysim %>%
as_tibble() %>%
ysim |>
as_tibble() |>
mutate(
id = as.character(row_number()),
age = round(.data$age / day2yr, 2)
Expand All @@ -159,15 +159,15 @@
if (format == "long") {
if (verbose) message("outputting long format data")
to_return <-
to_return %>%
to_return |>
pivot_longer(
cols = all_of(antigen_isos),
values_to = c("value"),
names_to = c("antigen_iso")
) %>%
) |>
structure(
format = "long"
) %>%
) |>
as_pop_data(
value = "value",
age = "age",
Expand All @@ -177,7 +177,7 @@
} else {
if (verbose) message("outputting wide format data")
to_return <-
to_return %>%
to_return |>

Check warning on line 180 in R/sim_pop_data.R

View check run for this annotation

Codecov / codecov/patch

R/sim_pop_data.R#L180

Added line #L180 was not covered by tests
structure(
class = c("pop_data_wide", class(to_return)),
format = "wide"
Expand All @@ -194,21 +194,22 @@
#'
#' `sim.cs()` was renamed to [sim_pop_data()] to create a more
#' consistent API.
#'
#' @keywords internal
sim.cs <- function(
n.smpl,
age.rng,
n.mc,
renew.params,
add.noise,
...) { # nolint: object_name_linter
#' @export
sim.cs <- function( # nolint: object_name_linter
n.smpl, # nolint: object_name_linter
age.rng, # nolint: object_name_linter
n.mc, # nolint: object_name_linter
renew.params, # nolint: object_name_linter
add.noise, # nolint: object_name_linter
...) { # nolint: object_name_linter
lifecycle::deprecate_soft("1.3.1", "sim.cs()", "sim_pop_data()")
sim_pop_data(
n_samples = n.smpl,
age_range = age.rng,
n_mcmc_samples = n.mc,
renew_params = renew.params,
add_noise = add.noise,
...)
...
)

Check warning on line 214 in R/sim_pop_data.R

View check run for this annotation

Codecov / codecov/patch

R/sim_pop_data.R#L213-L214

Added lines #L213 - L214 were not covered by tests
}
7 changes: 4 additions & 3 deletions R/sim_pop_data_multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
...) {
if (verbose) {
message("inputs to `sim_pop_data_multi()`:")
print(environment() %>% as.list())
print(environment() |> as.list())

Check warning on line 60 in R/sim_pop_data_multi.R

View check run for this annotation

Codecov / codecov/patch

R/sim_pop_data_multi.R#L60

Added line #L60 was not covered by tests
}

if (num_cores > 1L) {
Expand All @@ -69,7 +69,7 @@
num_cores <- 2L
} else {
# use all cores in devtools::test()
num_cores <- num_cores %>% check_parallel_cores()
num_cores <- num_cores |> check_parallel_cores()
}


Expand Down Expand Up @@ -104,7 +104,7 @@
sim_pop_data(
lambda = l,
...
) %>%
) |>
mutate(lambda.sim = l, cluster = n)
}
doParallel::stopImplicitCluster()
Expand All @@ -121,6 +121,7 @@
#' to create a more consistent API.
#'
#' @keywords internal
#' @export
sim.cs.multi <- function(...) { # nolint: object_name_linter
lifecycle::deprecate_soft("1.3.1", "sim.cs.multi()", "sim_pop_data_multi()")
sim_pop_data_multi(...)
Expand Down
Loading