Skip to content

Commit

Permalink
support list col output
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdefries committed Jan 25, 2024
1 parent 1a0741d commit a51e7ee
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions R/slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,6 @@ epi_slide_mean = function(x, col_name, ..., before, after, ref_time_values,
# Check we have an `epi_df` object
if (!inherits(x, "epi_df")) Abort("`x` must be of class `epi_df`.")

if (as_list_col) {
Warn("`as_list_col` is not supported for `epi_slide_mean`. This setting will be ignored")
}

user_provided_rtvs <- !missing(ref_time_values)
if (!user_provided_rtvs) {
ref_time_values <- unique(x$time_value)
Expand Down Expand Up @@ -636,6 +632,16 @@ epi_slide_mean = function(x, col_name, ..., before, after, ref_time_values,
result <- result[result$time_value %in% ref_time_values, ]
}

if (as_list_col) {
result[, result_col_name] <- purrr::map(result_col_name,
function(.x) {
tmp <- result[[.x]]
tmp[is.na(tmp)] <- list(NULL)
as.list(tmp)
}
)
}

if (!is_epi_df(result)) {
# `all_rows` and `as_list_col` handling strip epi_df format and metadata.
# Restore them.
Expand Down

0 comments on commit a51e7ee

Please sign in to comment.