Skip to content

Commit 4c766ad

Browse files
authored
Replace superseded purrr::transpose() with purrr::list_transpose() (#524)
1 parent 44f7c8c commit 4c766ad

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ importFrom(progressr,progressor)
187187
importFrom(progressr,with_progress)
188188
importFrom(purrr,compact)
189189
importFrom(purrr,keep)
190+
importFrom(purrr,list_transpose)
190191
importFrom(purrr,map)
191192
importFrom(purrr,map2_dbl)
192193
importFrom(purrr,map_chr)
@@ -196,7 +197,6 @@ importFrom(purrr,pmap_dbl)
196197
importFrom(purrr,quietly)
197198
importFrom(purrr,reduce)
198199
importFrom(purrr,safely)
199-
importFrom(purrr,transpose)
200200
importFrom(purrr,walk)
201201
importFrom(rlang,abort)
202202
importFrom(rlang,arg_match)

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
## Package
1717

18+
* Replaced use of `purrr::transpose()` with `purrr::list_transpose()` because the former is superseded. By @jamesmbaazam in #524 and reviewed by @seabbs.
1819
* Reduced the number of long-running examples. By @sbfnk in #459 and reviewed by @seabbs.
1920
* Changed all instances of arguments that refer to the maximum of a distribution to reflect the maximum. Previously this did, in some instance, refer to the length of the PMF. By @sbfnk in #468.
2021
* Fixed a bug in the bounds of delays when setting initial conditions. By @sbfnk in #474.

R/create.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,14 @@ create_stan_args <- function(stan = stan_opts(),
648648
##' The names are assigned to IDs
649649
##' @param weight Numeric, weight associated with delay priors; default: 1
650650
##' @return A list of variables as expected by the stan model
651-
##' @importFrom purrr transpose map
651+
##' @importFrom purrr list_transpose map
652652
##' @author Sebastian Funk
653653
create_stan_delays <- function(..., weight = 1) {
654654
dot_args <- list(...)
655655
## combine delays
656656
combined_delays <- unclass(c(...))
657657
## number of different non-empty types
658-
type_n <- unlist(purrr::transpose(dot_args)$n)
658+
type_n <- unlist(purrr::list_transpose(dot_args, simplify = FALSE)$n)
659659
## assign ID values to each type
660660
ids <- rep(0L, length(type_n))
661661
ids[type_n > 0] <- seq_len(sum(type_n > 0))

R/dist.R

+10-8
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,12 @@ gamma_dist_def <- function(shape, shape_sd,
355355

356356
dist <- data.table::data.table(
357357
model = rep("gamma", samples),
358-
params = purrr::transpose(
358+
params = purrr::list_transpose(
359359
list(
360360
shape = shape,
361361
scale = scale
362-
)
362+
),
363+
simplify = FALSE
363364
),
364365
max_value = rep(max_value, samples)
365366
)
@@ -445,11 +446,12 @@ lognorm_dist_def <- function(mean, mean_sd,
445446

446447
dist <- data.table::data.table(
447448
model = rep("lognormal", samples),
448-
params = purrr::transpose(
449+
params = purrr::list_transpose(
449450
list(
450451
mean = means,
451452
sd = sds
452-
)
453+
),
454+
simplify = FALSE
453455
),
454456
max_value = rep(max_value, samples)
455457
)
@@ -490,7 +492,7 @@ lognorm_dist_def <- function(mean, mean_sd,
490492
#'
491493
#' @return A `<dist_spec>` object summarising the bootstrapped distribution
492494
#' @author Sam Abbott
493-
#' @importFrom purrr transpose
495+
#' @importFrom purrr list_transpose
494496
#' @importFrom future.apply future_lapply
495497
#' @importFrom rstan extract
496498
#' @importFrom data.table data.table rbindlist
@@ -566,7 +568,7 @@ bootstrapped_dist_fit <- function(values, dist = "lognormal",
566568
)
567569

568570

569-
dist_samples <- purrr::transpose(dist_samples)
571+
dist_samples <- purrr::list_transpose(dist_samples, simplify = FALSE)
570572
dist_samples <- purrr::map(dist_samples, unlist)
571573
}
572574

@@ -1149,7 +1151,7 @@ dist_spec_plus <- function(e1, e2, tolerance = 0.001) {
11491151
#' @return Combined delay distributions (with class `<dist_spec>`)
11501152
#' @author Sebastian Funk
11511153
#' @method c dist_spec
1152-
#' @importFrom purrr transpose map
1154+
#' @importFrom purrr list_transpose map
11531155
c.dist_spec <- function(...) {
11541156
## process delay distributions
11551157
delays <- list(...)
@@ -1160,7 +1162,7 @@ c.dist_spec <- function(...) {
11601162
)
11611163
}
11621164
## transpose delays
1163-
delays <- purrr::transpose(delays)
1165+
delays <- purrr::list_transpose(delays, simplify = FALSE)
11641166
## convert back to arrays
11651167
delays <- purrr::map(delays, function(x) array(unlist(x)))
11661168
sum_args <- grep("^n($|_)", names(delays))

R/estimate_infections.R

-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@
6262
#' @inheritParams calc_CrIs
6363
#' @importFrom data.table data.table copy merge.data.table as.data.table
6464
#' @importFrom data.table setorder rbindlist melt .N setDT
65-
#' @importFrom purrr transpose
6665
#' @importFrom lubridate days
67-
#' @importFrom purrr transpose
6866
#' @importFrom futile.logger flog.threshold flog.warn flog.debug
6967
#' @importFrom checkmate assert_class assert_numeric assert_logical
7068
#' assert_string

R/simulate_infections.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#' @param verbose Logical defaults to [interactive()]. Should a progress bar
3030
#' (from `progressr`) be shown.
3131
#' @importFrom rstan extract sampling
32-
#' @importFrom purrr transpose map safely compact
32+
#' @importFrom purrr list_transpose map safely compact
3333
#' @importFrom future.apply future_lapply
3434
#' @importFrom progressr with_progress progressor
3535
#' @importFrom data.table rbindlist as.data.table
@@ -236,7 +236,7 @@ simulate_infections <- function(estimates,
236236
nends <- c(
237237
seq(batch_size, by = batch_size, length.out = batch_no - 1), samples
238238
)
239-
batches <- transpose(list(nstarts, nends))
239+
batches <- list_transpose(list(nstarts, nends), simplify = FALSE)
240240
} else {
241241
batches <- list(list(1, samples))
242242
}
@@ -265,7 +265,7 @@ simulate_infections <- function(estimates,
265265

266266
## join batches
267267
out <- compact(out)
268-
out <- transpose(out)
268+
out <- list_transpose(out, simplify = FALSE)
269269
out <- map(out, rbindlist)
270270

271271
## format output

0 commit comments

Comments
 (0)