Skip to content

Commit

Permalink
doc: update vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemetov committed Sep 26, 2024
1 parent c73b6c2 commit 40d7872
Show file tree
Hide file tree
Showing 21 changed files with 486 additions and 694 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
^.lintr$
^DEVELOPMENT.md$
man-roxygen
^.venv$
^sandbox.R$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ docs
renv/
renv.lock
.Rprofile
sandbox.R
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Imports:
tidyselect (>= 1.2.0),
tsibble,
utils,
vctrs
vctrs,
waldo
Suggests:
covidcast,
devtools,
Expand Down
4 changes: 2 additions & 2 deletions R/methods-epi_archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
#' library(dplyr)
#'
#' # Reference time points for which we want to compute slide values:
#' versions <- seq(as.Date("2020-06-01"),
#' versions <- seq(as.Date("2020-06-02"),
#' as.Date("2020-06-15"),
#' by = "1 day"
#' )
Expand Down Expand Up @@ -780,7 +780,7 @@ epix_detailed_restricted_mutate <- function(.data, ...) {
#' .versions = versions
#' ) %>%
#' ungroup() %>%
#' arrange(geo_value, time_value)
#' arrange(geo_value, version)
#'
#' # --- Advanced: ---
#'
Expand Down
6 changes: 5 additions & 1 deletion R/methods-epi_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ arrange_col_canonical.epi_df <- function(x, ...) {
x %>% dplyr::relocate(dplyr::all_of(cols), .before = 1)
}

#' Group an `epi_df` object by default keys
#' @param x an `epi_df`
#' @param exclude character vector of column names to exclude from grouping
#' @return a grouped `epi_df`
#' @export
group_epi_df <- function(x, exclude = character()) {
cols <- key_colnames(x, exclude = exclude)
Expand All @@ -440,7 +444,7 @@ group_epi_df <- function(x, exclude = character()) {
#' the resulting `epi_df` will have `geo_value` set to `"total"`.
#'
#' @param .x an `epi_df`
#' @param value_col character vector of the columns to aggregate
#' @param sum_cols character vector of the columns to aggregate
#' @param group_cols character vector of column names to group by. "time_value" is
#' included by default.
#' @return an `epi_df` object
Expand Down
12 changes: 5 additions & 7 deletions R/outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ detect_outlr <- function(x = seq_along(y), y,
#' group_by(geo_value) %>%
#' mutate(outlier_info = detect_outlr_rm(
#' x = time_value, y = cases
#' )) %>%
#' unnest(outlier_info)
#' ))
detect_outlr_rm <- function(x = seq_along(y), y, n = 21,
log_transform = FALSE,
detect_negatives = FALSE,
Expand All @@ -189,7 +188,7 @@ detect_outlr_rm <- function(x = seq_along(y), y, n = 21,

# Calculate lower and upper thresholds and replacement value
z <- z %>%
epi_slide(fitted = median(y), .window_size = n, .align = "center") %>%
epi_slide(fitted = median(y, na.rm = TRUE), .window_size = n, .align = "center") %>%
dplyr::mutate(resid = y - fitted) %>%
roll_iqr(
n = n,
Expand Down Expand Up @@ -256,9 +255,8 @@ detect_outlr_rm <- function(x = seq_along(y), y, n = 21,
#' group_by(geo_value) %>%
#' mutate(outlier_info = detect_outlr_stl(
#' x = time_value, y = cases,
#' seasonal_period = 7
#' )) %>% # weekly seasonality for daily data
#' unnest(outlier_info)
#' seasonal_period = 7 # weekly seasonality for daily data
#' ))
detect_outlr_stl <- function(x = seq_along(y), y,
n_trend = 21,
n_seasonal = 21,
Expand Down Expand Up @@ -359,7 +357,7 @@ roll_iqr <- function(z, n, detection_multiplier, min_radius,

z %>%
epi_slide(
roll_iqr = stats::IQR(resid),
roll_iqr = stats::IQR(resid, na.rm = TRUE),
.window_size = n, .align = "center"
) %>%
dplyr::mutate(
Expand Down
10 changes: 4 additions & 6 deletions R/revision_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ revision_summary <- function(epi_arch,
should_compactify = TRUE) {
arg <- names(eval_select(rlang::expr(c(...)), allow_rename = FALSE, data = epi_arch$DT))
if (length(arg) == 0) {
first_non_key <- !(names(epi_arch$DT) %in% c(key_colnames(epi_arch), "version"))
arg <- names(epi_arch$DT)[first_non_key][1]
# Choose the first column that's not a key or version
arg <- setdiff(names(epi_arch$DT), c(key_colnames(epi_arch), "version"))[[1]]
} else if (length(arg) > 1) {
cli_abort("Not currently implementing more than one column at a time. Run each separately")
}
Expand All @@ -99,11 +99,9 @@ revision_summary <- function(epi_arch,
#
# revision_tibble
keys <- key_colnames(epi_arch)
names(epi_arch$DT)

revision_behavior <-
epi_arch$DT %>%
select(c(geo_value, time_value, all_of(keys), version, !!arg))
revision_behavior <- epi_arch$DT %>%
select(all_of(unique(c("geo_value", "time_value", keys, "version", arg))))
if (!is.null(min_waiting_period)) {
revision_behavior <- revision_behavior %>%
filter(abs(time_value - as.Date(epi_arch$versions_end)) >= min_waiting_period)
Expand Down
2 changes: 1 addition & 1 deletion R/slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ epi_slide_opt <- function(
# positions of user-provided `col_names` into string column names. We avoid
# using `names(pos)` directly for robustness and in case we later want to
# allow users to rename fields via tidyselection.
if (class(quo_get_expr(enquo(.col_names))) == "character") {
if (inherits(quo_get_expr(enquo(.col_names)), "character")) {
pos <- eval_select(dplyr::all_of(.col_names), data = .x, allow_rename = FALSE)
} else {
pos <- eval_select(enquo(.col_names), data = .x, allow_rename = FALSE)
Expand Down
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ articles:
- aggregation
- outliers
- archive
- advanced
- compactify

repo:
Expand Down
2 changes: 1 addition & 1 deletion man-roxygen/basic-slide-details.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' boundary of the dataset) and will attempt to perform the computation
#' anyway. The issue of what to do with partial computations (those run on
#' incomplete windows) is therefore left up to the user, either through the
#' specified function or formula `f`, or through post-processing.
#' specified function or formula, or through post-processing.
#'
#' Let's look at some window examples, assuming that the reference time value
#' is "tv". With .align = "right" and .window_size = 3, the window will be:
Expand Down
3 changes: 1 addition & 2 deletions man/detect_outlr_rm.Rd

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

5 changes: 2 additions & 3 deletions man/detect_outlr_stl.Rd

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

2 changes: 1 addition & 1 deletion man/epi_slide.Rd

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

4 changes: 2 additions & 2 deletions man/epix_slide.Rd

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

Loading

0 comments on commit 40d7872

Please sign in to comment.