Skip to content

Commit 382485d

Browse files
authored
Merge pull request #623 from cmu-delphi/lint-for-0.11
Lint + lint config updates for 0.11
2 parents da3fa5f + fae8200 commit 382485d

16 files changed

+61
-73
lines changed

.lintr

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
linters: linters_with_defaults(
22
line_length_linter(120),
3-
cyclocomp_linter = NULL,
43
object_length_linter(length = 40L)
54
)
65
exclusions: list(

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: epiprocess
33
Title: Tools for basic signal processing in epidemiology
4-
Version: 0.10.5
4+
Version: 0.11.0
55
Authors@R: c(
66
person("Jacob", "Bien", role = "ctb"),
77
person("Logan", "Brooks", , "[email protected]", role = c("aut", "cre")),

R/archive.R

+3-5
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,13 @@ is_locf <- function(vec, abs_tol, is_key) { # nolint: object_usage_linter
497497
if (is.vector(vec, mode = "numeric") && !is_key) {
498498
# (integer or double vector, no class (& no dims); maybe names, which we'll
499499
# ignore like `vec_equal`); not a key column
500-
res <- unname(if_else(
500+
unname(if_else(
501501
!is.na(vec) & !is.na(lag_vec),
502502
abs(vec - lag_vec) <= abs_tol,
503503
is.na(vec) & is.na(lag_vec)
504504
))
505-
return(res)
506505
} else {
507-
res <- vec_equal(vec, lag_vec, na_equal = TRUE)
508-
return(res)
506+
vec_equal(vec, lag_vec, na_equal = TRUE)
509507
}
510508
}
511509

@@ -808,5 +806,5 @@ clone <- function(x) {
808806
#' @export
809807
clone.epi_archive <- function(x) {
810808
x$DT <- data.table::copy(x$DT)
811-
return(x)
809+
x
812810
}

R/correlation.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ epi_cor <- function(x, var1, var2, dt1 = 0, dt2 = 0, shift_by = geo_value, # nol
120120
# Function to perform time shifts, lag or lead
121121
shift <- function(var, n) {
122122
if (n < 0) {
123-
return(dplyr::lag(var, -n))
123+
dplyr::lag(var, -n)
124124
} else {
125-
return(dplyr::lead(var, n))
125+
dplyr::lead(var, n)
126126
}
127127
}

R/epi_df.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ as_epi_df <- function(x, ...) {
218218
#' @export
219219
as_epi_df.epi_df <- function(x, ...) {
220220
x <- ungroup(x)
221-
return(x)
221+
x
222222
}
223223

224224
#' @rdname epi_df

R/grouped_epi_archive.R

+11-13
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ new_grouped_epi_archive <- function(x, vars, drop) {
7676
private$vars <- vars
7777
private$drop <- drop
7878

79-
return(structure(
79+
structure(
8080
list(
8181
private = private
8282
),
8383
class = "grouped_epi_archive"
84-
))
84+
)
8585
}
8686

8787

@@ -431,7 +431,7 @@ epix_slide.grouped_epi_archive <- function(
431431
}
432432

433433
# Fast conversion:
434-
return(validate_tibble(new_tibble(res)))
434+
validate_tibble(new_tibble(res))
435435
}
436436

437437
out <- lapply(.versions, function(.version) {
@@ -493,16 +493,14 @@ epix_slide.grouped_epi_archive <- function(
493493
}
494494
}
495495

496-
return(
497-
dplyr::bind_rows(dplyr::group_map( # note: output will be ungrouped
498-
dplyr::group_by(as_of_df, !!!syms(.x$private$vars), .drop = .x$private$drop),
499-
group_map_fn,
500-
.slide_comp = .slide_comp, ...,
501-
.version = .version,
502-
.new_col_name = .new_col_name,
503-
.keep = TRUE
504-
))
505-
)
496+
dplyr::bind_rows(dplyr::group_map( # note: output will be ungrouped
497+
dplyr::group_by(as_of_df, !!!syms(.x$private$vars), .drop = .x$private$drop),
498+
group_map_fn,
499+
.slide_comp = .slide_comp, ...,
500+
.version = .version,
501+
.new_col_name = .new_col_name,
502+
.keep = TRUE
503+
))
506504
})
507505
# Combine output into a single tibble (allowing for packed columns)
508506
out <- vctrs::vec_rbind(!!!out)

R/growth_rate.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ growth_rate <- function(
192192
a <- mean(yy[left])
193193
hh <- mean(xx[right]) - mean(xx[left])
194194
if (log_scale) {
195-
return((b - a) / hh)
195+
(b - a) / hh
196196
} else {
197-
return((b / a - 1) / hh)
197+
(b / a - 1) / hh
198198
}
199199
} else {
200200
# Linear regression
@@ -203,9 +203,9 @@ growth_rate <- function(
203203
b <- sum(xm * ym) / sum(xm^2)
204204
a <- mean(yy - b * xx)
205205
if (log_scale) {
206-
return(b)
206+
b
207207
} else {
208-
return(b / (a + b * x_ref))
208+
b / (a + b * x_ref)
209209
}
210210
}
211211
})
@@ -381,5 +381,5 @@ parse_trendfilter_params <- function(params) {
381381
# If we got here, we fit TF. There are two possibilities:
382382
# 1. df is NULL and lambda is a scalar
383383
# 2. df is numeric and lambda is either NULL or a vector (vec_lambda = TRUE)
384-
return(params)
384+
params
385385
}

R/methods-epi_archive.R

+4-5
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,10 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
604604
out_archive <- .data
605605
out_archive$DT <- out_dt
606606
request_names <- names(col_modify_cols)
607-
return(list(
607+
list(
608608
archive = out_archive,
609609
request_names = request_names
610-
))
610+
)
611611
# (We might also consider special-casing when `mutate` hands back something
612612
# equivalent (in some sense) to the input (probably only encountered when
613613
# we're dealing with `group_by`), and using just `$DT`, not a shallow copy,
@@ -879,8 +879,7 @@ epix_slide.epi_archive <- function(
879879
#' @noRd
880880
epix_slide_versions_default <- function(ea) {
881881
versions_with_updates <- c(ea$DT$version, ea$versions_end)
882-
ref_time_values <- tidyr::full_seq(versions_with_updates, guess_period(versions_with_updates))
883-
return(ref_time_values)
882+
tidyr::full_seq(versions_with_updates, guess_period(versions_with_updates))
884883
}
885884

886885

@@ -920,7 +919,7 @@ epix_truncate_versions_after.epi_archive <- function(x, max_version) {
920919
x$clobberable_versions_start <- NA
921920
}
922921
x$versions_end <- max_version
923-
return(x)
922+
x
924923
}
925924

926925

R/methods-epi_df.R

+10-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ as_tibble.epi_df <- function(x, ...) {
1717
# first instead.
1818
destructured <- tibble::as_tibble(vctrs::vec_data(x), ...)
1919
if (attr(x, "decay_to_tibble") %||% TRUE) {
20-
return(destructured)
20+
destructured
2121
} else {
2222
# We specially requested via attr not to decay epi_df-ness but to drop any
2323
# grouping.
@@ -39,12 +39,10 @@ as_tibble.epi_df <- function(x, ...) {
3939
#' @export
4040
as_tsibble.epi_df <- function(x, key, ...) {
4141
if (missing(key)) key <- c("geo_value", attributes(x)$metadata$other_keys)
42-
return(
43-
as_tsibble(
44-
tibble::as_tibble(x),
45-
key = tidyselect::all_of(key), index = "time_value",
46-
...
47-
)
42+
as_tsibble(
43+
tibble::as_tibble(x),
44+
key = tidyselect::all_of(key), index = "time_value",
45+
...
4846
)
4947
}
5048

@@ -351,8 +349,8 @@ unnest.epi_df <- function(data, ...) {
351349
# Simple reclass function
352350
reclass <- function(x, metadata) {
353351
class(x) <- unique(c("epi_df", class(x)))
354-
attributes(x)$metadata <- metadata
355-
return(x)
352+
attr(x, "metadata") <- metadata
353+
x
356354
}
357355

358356
#' Arrange an epi_df into a standard order
@@ -376,7 +374,7 @@ arrange_canonical.default <- function(x, ...) {
376374
cli::cli_abort(c(
377375
"`arrange_canonical()` is only meaningful for an {.cls epi_df}."
378376
))
379-
return(x)
377+
x
380378
}
381379

382380
#' @export
@@ -397,7 +395,7 @@ arrange_row_canonical.default <- function(x, ...) {
397395
cli::cli_abort(c(
398396
"`arrange_row_canonical()` is only meaningful for an {.cls epi_df}."
399397
))
400-
return(x)
398+
x
401399
}
402400

403401
#' @export
@@ -417,7 +415,7 @@ arrange_col_canonical.default <- function(x, ...) {
417415
cli::cli_abort(c(
418416
"`arrange_col_canonical()` is only meaningful for an {.cls epi_df}."
419417
))
420-
return(x)
418+
x
421419
}
422420

423421
#' @export

R/outliers.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ detect_outlr <- function(x = seq_along(y), y,
122122

123123
# Update column names with model abbreviation
124124
colnames(results) <- paste(abbr, colnames(results), sep = "_")
125-
return(results)
125+
results
126126
})
127127

128128
# Combine information about detected outliers

R/revision_analysis.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ get_last_run <- function(bool_vec, values_from) {
280280
f_no_na <- function(f, x) {
281281
x <- x[!is.na(x)]
282282
if (length(x) == 0) {
283-
return(Inf)
283+
Inf
284284
} else {
285-
return(f(x))
285+
f(x)
286286
}
287287
}
288288

@@ -313,8 +313,8 @@ time_delta_summary <- function(time_delta, time_type) {
313313
check.names = FALSE
314314
) %>%
315315
mutate(across(c(min, median, mean, max), ~ .x * unit_time_delta(time_type)))
316-
return(res)
316+
res
317317
} else {
318-
return(data.frame())
318+
data.frame()
319319
}
320320
}

R/slide.R

+9-9
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ epi_slide <- function(
281281
i <<- i + 1L
282282
.slide_comp(.x, .group_key, .ref_time_value, ...)
283283
}
284-
return(slide_comp_wrapper)
284+
slide_comp_wrapper
285285
}
286286

287287
# - If .x is not grouped, then the trivial group is applied:
@@ -398,11 +398,11 @@ epi_slide_one_group <- function(
398398
# back.
399399
return_types <- purrr::map_chr(slide_values_list, function(x) {
400400
if (is.data.frame(x)) {
401-
return("data.frame")
401+
"data.frame"
402402
} else if (vctrs::obj_is_vector(x) && is.null(vctrs::vec_names(x))) {
403-
return("vector")
403+
"vector"
404404
} else {
405-
return("other")
405+
"other"
406406
}
407407
}) %>% unique()
408408
# Returned values must be data.frame or vector.
@@ -512,7 +512,7 @@ epi_slide_one_group <- function(
512512
res[[.new_col_name]] <- slide_values
513513
}
514514

515-
return(res)
515+
res
516516
}
517517

518518
get_before_after_from_window <- function(window_size, align, time_type) {
@@ -544,7 +544,7 @@ get_before_after_from_window <- function(window_size, align, time_type) {
544544
after <- window_size - 1
545545
}
546546
}
547-
return(list(before = before, after = after))
547+
list(before = before, after = after)
548548
}
549549

550550
#' Optimized slide functions for common cases
@@ -952,7 +952,7 @@ epi_slide_opt <- function(
952952
}
953953
}
954954

955-
return(.data_group)
955+
.data_group
956956
}
957957

958958
result <- mutate(.x, .real = TRUE) %>%
@@ -1147,9 +1147,9 @@ full_date_seq <- function(x, before, after, time_type) {
11471147
}
11481148
}
11491149

1150-
return(list(
1150+
list(
11511151
all_dates = all_dates,
11521152
pad_early_dates = pad_early_dates,
11531153
pad_late_dates = pad_late_dates
1154-
))
1154+
)
11551155
}

R/utils.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ guess_geo_type <- function(geo_value) {
617617
}
618618
}
619619

620-
return("custom")
620+
"custom"
621621
}
622622

623623

@@ -679,7 +679,7 @@ time_column_names <- function() {
679679
)
680680
substitutions <- upcase_snake_case(substitutions)
681681
names(substitutions) <- rep("time_value", length(substitutions))
682-
return(substitutions)
682+
substitutions
683683
}
684684
#
685685
#' potential geo_value columns
@@ -696,7 +696,7 @@ geo_column_names <- function() {
696696
)
697697
substitutions <- upcase_snake_case(substitutions)
698698
names(substitutions) <- rep("geo_value", length(substitutions))
699-
return(substitutions)
699+
substitutions
700700
}
701701

702702
#' potential version columns
@@ -711,7 +711,7 @@ version_column_names <- function() {
711711
)
712712
substitutions <- upcase_snake_case(substitutions)
713713
names(substitutions) <- rep("version", length(substitutions))
714-
return(substitutions)
714+
substitutions
715715
}
716716

717717
#' rename potential time_value columns
@@ -753,7 +753,7 @@ guess_column_name <- function(x, column_name, substitutions) {
753753
}
754754
)
755755
}
756-
return(x)
756+
x
757757
}
758758

759759
##########

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ edf
120120
#>
121121
#> # A tibble: 2,808 × 4
122122
#> geo_value time_value cases_cumulative cases_daily
123-
#> * <chr> <date> <dbl> <dbl>
123+
#> <chr> <date> <dbl> <dbl>
124124
#> 1 ca 2020-03-01 19 19
125125
#> 2 ca 2020-03-02 23 4
126126
#> 3 ca 2020-03-03 29 6
@@ -144,7 +144,7 @@ edf
144144
#>
145145
#> # A tibble: 2,808 × 5
146146
#> geo_value time_value cases_cumulative cases_daily smoothed_cases_daily
147-
#> * <chr> <date> <dbl> <dbl> <dbl>
147+
#> <chr> <date> <dbl> <dbl> <dbl>
148148
#> 1 ca 2020-03-01 19 19 19
149149
#> 2 ca 2020-03-02 23 4 11.5
150150
#> 3 ca 2020-03-03 29 6 9.67

0 commit comments

Comments
 (0)