-
Notifications
You must be signed in to change notification settings - Fork 8
Replaced n in epi_slide
and epix_slide
#203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 66 commits
1cf5aec
d730876
2d96c5a
4c45aa5
f06b7fe
8683249
3f42e60
08b22e5
d5a402c
dfc3566
62ce720
5ee25e6
ee9e9f6
ce44a28
7a32fbd
2a0c97e
35f53d4
0258a03
c1369c2
e2172a3
04302b6
feb0f47
08a580d
666c4f7
3134a55
bb39209
5984d8d
b68af0b
b3229f2
d18d98c
121f9d2
35811f1
06a6190
37b3815
f6e8795
ee10963
05d84ca
846b6ca
d55e6b8
1158c8a
bbf5d6b
b55d411
b22ace3
feea2f4
1038e15
6e2b207
77b5bb9
db99a67
0456aff
950ee8c
d43cede
039f33f
93738aa
8c601f8
cfe2b55
6f91a55
271ffe6
b0d751b
9f46090
0498777
b9b9e6a
28a9c12
b407fdd
d14c0e8
2b8690f
3bd1368
581648d
9980ec2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -584,23 +584,24 @@ epi_archive = | |
#' details. | ||
#' @importFrom data.table key | ||
#' @importFrom rlang !! !!! enquo quo_is_missing enquos is_quosure sym syms | ||
slide = function(f, ..., n, group_by, ref_time_values, | ||
slide = function(f, ..., max_version_gap, group_by, | ||
ref_versions, | ||
time_step, new_col_name = "slide_value", | ||
as_list_col = FALSE, names_sep = "_", | ||
all_rows = FALSE) { | ||
# If missing, then set ref time values to be everything; else make | ||
# sure we intersect with observed time values | ||
if (missing(ref_time_values)) { | ||
ref_time_values = unique(self$DT$time_value) | ||
if (missing(ref_versions)) { | ||
ref_versions = unique(self$DT$version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on discussion with Ryan, we shouldn't rename |
||
} | ||
else { | ||
ref_time_values = ref_time_values[ref_time_values %in% | ||
ref_versions = ref_versions[ref_versions %in% | ||
unique(self$DT$time_value)] | ||
} | ||
|
||
# If a custom time step is specified, then redefine units | ||
before_num = n-1 | ||
if (!missing(time_step)) before_num = time_step(n-1) | ||
before_num = max_version_gap-1 | ||
if (!missing(time_step)) before_num = time_step(max_version_gap-1) | ||
|
||
# What to group by? If missing, set according to internal keys; | ||
# otherwise, tidyselect. | ||
|
@@ -619,7 +620,7 @@ epi_archive = | |
# Computation for one group, one time value | ||
comp_one_grp = function(.data_group, | ||
f, ..., | ||
time_value, | ||
version, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In line with the above, please call this |
||
key_vars, | ||
new_col) { | ||
# Carry out the specified computation | ||
|
@@ -665,21 +666,22 @@ epi_archive = | |
|
||
# Note that we've already recycled comp value to make size stable, | ||
# so tibble() will just recycle time value appropriately | ||
return(tibble::tibble(time_value = time_value, | ||
return(tibble::tibble(version = version, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, we've put such changes on hold / are still discussing; this should be |
||
!!new_col := comp_value)) | ||
} | ||
|
||
# If f is not missing, then just go ahead, slide by group | ||
if (!missing(f)) { | ||
|
||
if (rlang::is_formula(f)) f = rlang::as_function(f) | ||
|
||
x = purrr::map_dfr(ref_time_values, function(t) { | ||
x = purrr::map_dfr(ref_versions, function(t) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename |
||
self$as_of(t, min_time_value = t - before_num) %>% | ||
tibble::as_tibble() %>% | ||
dplyr::group_by(!!!group_by) %>% | ||
dplyr::group_modify(comp_one_grp, | ||
f = f, ..., | ||
time_value = t, | ||
version = t, | ||
key_vars = key_vars, | ||
new_col = new_col, | ||
.keep = TRUE) %>% | ||
|
@@ -701,13 +703,13 @@ epi_archive = | |
f = function(x, quo, ...) rlang::eval_tidy(quo, x) | ||
new_col = sym(names(rlang::quos_auto_name(quos))) | ||
|
||
x = purrr::map_dfr(ref_time_values, function(t) { | ||
x = purrr::map_dfr(ref_versions, function(t) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
self$as_of(t, min_time_value = t - before_num) %>% | ||
tibble::as_tibble() %>% | ||
dplyr::group_by(!!!group_by) %>% | ||
dplyr::group_modify(comp_one_grp, | ||
f = f, quo = quo, | ||
time_value = t, | ||
version = t, | ||
key_vars = key_vars, | ||
new_col = new_col, | ||
.keep = TRUE) %>% | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on discussion with Ryan,
max_version_gap
should be calledbefore
.