Skip to content

Commit 4d85b6d

Browse files
committed
make lintr happy
1 parent 02831f4 commit 4d85b6d

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

R/dist.R

+19-19
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#' )
8585
dist_skel <- function(n, dist = FALSE, cum = TRUE, model,
8686
discrete = FALSE, params, max_value = 120) {
87-
if (model %in% "exp") {
87+
if (model == "exp") {
8888
# define support functions for exponential dist
8989
rdist <- function(n) {
9090
rexp(n, params$rate)
@@ -97,7 +97,7 @@ dist_skel <- function(n, dist = FALSE, cum = TRUE, model,
9797
pexp(n, params$rate)) /
9898
pexp(max_value + 1, params$rate)
9999
}
100-
} else if (model %in% "gamma") {
100+
} else if (model == "gamma") {
101101
rdist <- function(n) {
102102
rgamma(n, params$shape, params$scale)
103103
}
@@ -110,7 +110,7 @@ dist_skel <- function(n, dist = FALSE, cum = TRUE, model,
110110
pgamma(n, params$shape, params$scale)) /
111111
pgamma(max_value + 1, params$shape, params$scale)
112112
}
113-
} else if (model %in% "lognormal") {
113+
} else if (model == "lognormal") {
114114
rdist <- function(n) {
115115
rlnorm(n, params$mean, params$sd)
116116
}
@@ -141,16 +141,16 @@ dist_skel <- function(n, dist = FALSE, cum = TRUE, model,
141141

142142
# define internal sampling function
143143
inner_skel <- function(n, dist = FALSE, cum = TRUE, max_value = NULL) {
144-
if (!dist) {
145-
rdist(n)
146-
} else {
144+
if (dist) {
147145
if (cum) {
148146
ret <- pdist(n)
149147
} else {
150148
ret <- ddist(n)
151149
}
152150
ret[ret > 1] <- NA_real_
153151
return(ret)
152+
} else {
153+
rdist(n)
154154
}
155155
}
156156

@@ -246,14 +246,14 @@ dist_fit <- function(values = NULL, samples = 1000, cores = 1,
246246

247247
model <- stanmodels$dist_fit
248248

249-
if (dist %in% "exp") {
249+
if (dist == "exp") {
250250
data$dist <- 0
251251
data$lam_mean <- array(mean(values))
252-
} else if (dist %in% "lognormal") {
252+
} else if (dist == "lognormal") {
253253
data$dist <- 1
254254
data$prior_mean <- array(log(mean(values)))
255255
data$prior_sd <- array(log(sd(values)))
256-
} else if (dist %in% "gamma") {
256+
} else if (dist == "gamma") {
257257
data$dist <- 2
258258
data$prior_mean <- array(mean(values))
259259
data$prior_sd <- array(sd(values))
@@ -705,10 +705,10 @@ sample_approx_dist <- function(cases = NULL,
705705
direction = "backwards",
706706
type = "sample",
707707
truncate_future = TRUE) {
708-
if (type %in% "sample") {
709-
if (direction %in% "backwards") {
708+
if (type == "sample") {
709+
if (direction == "backwards") {
710710
direction_fn <- rev
711-
} else if (direction %in% "forwards") {
711+
} else if (direction == "forwards") {
712712
direction_fn <- function(x) {
713713
x
714714
}
@@ -735,12 +735,12 @@ sample_approx_dist <- function(cases = NULL,
735735

736736

737737
# set dates order based on direction mapping
738-
if (direction %in% "backwards") {
738+
if (direction == "backwards") {
739739
dates <- seq(min(cases$date) - lubridate::days(length(draw) - 1),
740740
max(cases$date),
741741
by = "days"
742742
)
743-
} else if (direction %in% "forwards") {
743+
} else if (direction == "forwards") {
744744
dates <- seq(min(cases$date),
745745
max(cases$date) + lubridate::days(length(draw) - 1),
746746
by = "days"
@@ -765,17 +765,17 @@ sample_approx_dist <- function(cases = NULL,
765765
,
766766
cum_cases := cumsum(cases)
767767
][cum_cases != 0][, cum_cases := NULL]
768-
} else if (type %in% "median") {
768+
} else if (type == "median") {
769769
shift <- as.integer(
770770
median(as.integer(dist_fn(1000, dist = FALSE)), na.rm = TRUE)
771771
)
772772

773-
if (direction %in% "backwards") {
773+
if (direction == "backwards") {
774774
mapped_cases <- data.table::copy(cases)[
775775
,
776776
date := date - lubridate::days(shift)
777777
]
778-
} else if (direction %in% "forwards") {
778+
} else if (direction == "forwards") {
779779
mapped_cases <- data.table::copy(cases)[
780780
,
781781
date := date + lubridate::days(shift)
@@ -788,7 +788,7 @@ sample_approx_dist <- function(cases = NULL,
788788
}
789789

790790
# filter out future cases
791-
if (direction %in% "forwards" && truncate_future) {
791+
if (direction == "forwards" && truncate_future) {
792792
max_date <- max(cases$date)
793793
mapped_cases <- mapped_cases[date <= max_date]
794794
}
@@ -1143,7 +1143,7 @@ dist_spec_plus <- function(e1, e2, tolerance = 0.001) {
11431143
#' @author Sebastian Funk
11441144
#' @method c dist_spec
11451145
#' @importFrom purrr transpose map
1146-
`c.dist_spec` <- function(...) {
1146+
c.dist_spec <- function(...) {
11471147
## process delay distributions
11481148
delays <- list(...)
11491149
if (!(all(vapply(delays, is, FALSE, "dist_spec")))) {

0 commit comments

Comments
 (0)