Skip to content
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

Km compactify rectify #101

Merged
merged 114 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
636f212
Added some details for compactify
kenmawer May 13, 2022
05a4804
Added compactify variable with check.
kenmawer May 16, 2022
7760ce4
Updated function.
kenmawer May 16, 2022
fe1f2d8
Put !!! to indicate incomplete part.
kenmawer May 16, 2022
1268bb7
Shortened code
kenmawer May 16, 2022
56859cb
More code updates, including updates for vignette.
kenmawer May 17, 2022
bd4daf3
Put in new changes to vignette.
kenmawer May 17, 2022
a6d6975
Merge branch 'main' of https://github.com/dajmcdon/epiprocess into km…
kenmawer May 17, 2022
084bf8c
Added function to remove LOCF. This was copy-pasted while working out…
kenmawer May 20, 2022
d6a5fed
Still need to figure out how to get this to not give me a null dataset.
kenmawer May 20, 2022
87c487d
Fixed a typo on the code. I still haven't finished it.
kenmawer May 20, 2022
22937ae
Changed some text and fixed a typo.
kenmawer May 21, 2022
7310d22
Add a comment about code
kenmawer May 21, 2022
5eb4bdd
Put in a code stub for compactify testing.
kenmawer May 31, 2022
82756d5
Made tests and fixed a bug.
kenmawer May 31, 2022
97a2161
There's still work to do in ensuring the LOCF rows are printed properly!
kenmawer May 31, 2022
21d3d55
Fixed tests, LOCF rows still need to be printed.
kenmawer May 31, 2022
ffb32fe
Added warnings for LOCF.
kenmawer Jun 1, 2022
fd1c26a
Updated testing and warnings.
kenmawer Jun 1, 2022
cbdf9dd
Updated testing.
kenmawer Jun 1, 2022
c417f56
Still needs updating so tests pass. No longer using delphi.epidata.
kenmawer Jun 9, 2022
fef7377
Changed how LOCF checking will work. (Still needs work.)
kenmawer Jun 9, 2022
b142442
Added updates and changed some names.
kenmawer Jun 9, 2022
f7b353b
Changed LOCF check
kenmawer Jun 9, 2022
46628ca
Updated archive code.
kenmawer Jun 10, 2022
5479dd8
Improved LOCF filtering by treating NA's as if they are LOCF's due to…
kenmawer Jun 11, 2022
4f0ee0d
Modified arrange function to also account for other_keys.
kenmawer Jun 13, 2022
5420261
Update comment on RStudio.
kenmawer Jun 13, 2022
c66cb4e
Updated LOCF checking to take out redundancies.
kenmawer Jun 13, 2022
0a924be
Greatly improved as to actually test LOCF with more control over valu…
kenmawer Jun 13, 2022
b0d68e8
Improved tests to account for multiple values.
kenmawer Jun 14, 2022
2d4cd05
Updated vignette with an example.
kenmawer Jun 14, 2022
e4d15c6
Updated a few changes based on pull request comments.
kenmawer Jun 16, 2022
ff64463
Cleared up ifelse, improved printing and updated descriptions.
kenmawer Jun 16, 2022
e9bd8ab
Added a few more changes on the vignette and with the warning message.
kenmawer Jun 16, 2022
ba4f933
Fixed as_epi_archive on covidcast to be more clear about what is does…
kenmawer Jun 16, 2022
146b99d
Updated.
kenmawer Jun 16, 2022
716f8f3
Added a test (not finished yet) to test as_of.
kenmawer Jun 16, 2022
3712481
Added test for testing as_of in conjunction with compactify.
kenmawer Jun 16, 2022
2443419
Made test more descriptive.
kenmawer Jun 16, 2022
6185b78
Fixed error with if_else
kenmawer Jun 16, 2022
ec2960d
Updated vignette.
kenmawer Jun 16, 2022
07808fe
Updated warning message to be more clear.
kenmawer Jun 16, 2022
f6fde05
Updated comments.
kenmawer Jun 16, 2022
7c4d9b4
Fixed spacing with tests.
kenmawer Jun 17, 2022
c042e1d
Fix a missing `dplyr::`
lcbrooks Jun 18, 2022
8f36d44
Fix warnings&errors in examples&tests, keep archive_cases_dv in sync
lcbrooks Jun 18, 2022
e90a95a
Pulled from main.
kenmawer Jun 21, 2022
1be2b37
Added a feature for time of compactify.
kenmawer Jun 21, 2022
9a5d0a7
Basic template (not documented yet).
kenmawer Jun 21, 2022
1d455c0
Updated broken <<<<< code.
kenmawer Jun 21, 2022
cef2e4b
Pulled from main, fixed changes.
kenmawer Jun 21, 2022
f967522
Also need to commit this.
kenmawer Jun 21, 2022
8ec0b0b
Fixed accidentally deleted comment.
kenmawer Jun 21, 2022
4ec8bbf
Fixed formatting issue.
kenmawer Jun 21, 2022
f93bd71
This new branch is for test rectification due to new datasets. I also…
kenmawer Jun 21, 2022
2424251
Updated test to use new dataset similar to old one.
kenmawer Jun 21, 2022
07bce50
Broke up the archive vignette to create a vignette for compactify, wh…
kenmawer Jun 21, 2022
a309f0b
Updated incorrect code and vignette for more details.
kenmawer Jun 21, 2022
78f3dca
Removed comment.
kenmawer Jun 21, 2022
a24dc21
Replaced incorrect dataset.
kenmawer Jun 21, 2022
d7c56d3
Updated documentation.
kenmawer Jun 22, 2022
2f8735a
Updated this to show a plot of times with and without LOCF.
kenmawer Jun 22, 2022
8870205
Merged upstream; fixed DESCRIPTION conflict.
kenmawer Jun 28, 2022
8b4f86b
Resolved conflicts.
kenmawer Jun 28, 2022
278d43e
Merge branch 'cmu-delphi/main' into km-compactify_time
kenmawer Jun 29, 2022
c1075b2
Committed changes for #118.
kenmawer Jun 29, 2022
8b2ee2b
Added changes relating to PR #115.
kenmawer Jun 29, 2022
4ac9413
km-compactifify_rectify withouot any errors.
kenmawer Jun 29, 2022
d61faaf
Merge branch 'main' into km-compactify_rectify
kenmawer Jun 30, 2022
929c300
Clarify compactify testing code
lcbrooks Jun 30, 2022
4047e3d
Fixed broken code.
kenmawer Jul 4, 2022
3f276f9
Apply code formatting to an `epi_archive` example
lcbrooks Jul 1, 2022
be4a0cd
Revise `compactify` warning text and assign it a(nother) class
lcbrooks Jul 1, 2022
8a9326c
Emit some help on `archive_cases_dv` eval errors during `unregister`
lcbrooks Jul 4, 2022
c9d983c
Merge branch 'main' into km-compactify_rectify
kenmawer Jul 5, 2022
b3ddc3d
Add `clobberable_versions_start`, `observed_versions_end` params
lcbrooks Jul 5, 2022
5be42ed
Merge remote-tracking branch 'dajmcdon/km-compactify_rectify' into km…
lcbrooks Jul 6, 2022
2a20004
Add back explanation about reconstructing sample archive from stored DT
lcbrooks Jul 6, 2022
bcb48ff
Go back to using NA to indicate no clobberable versions
lcbrooks Jul 6, 2022
6f5b177
Re-`document`
lcbrooks Jul 6, 2022
b2cb48b
Merge branch 'main' into km-compactify_rectify
kenmawer Jul 11, 2022
c65c538
This still won't pass checks.
kenmawer Jul 11, 2022
f826218
Add epix_fill_through_version, overhaul epix_merge; needs extra work
lcbrooks Jul 21, 2022
140b20c
Merge remote-tracking branch 'dajmcdon/km-compactify_rectify' into km…
lcbrooks Jul 21, 2022
3595607
Fix "always compactifies" epix_merge doc, be precise about mutation i…
lcbrooks Jul 22, 2022
22aa417
Fix example archive to match old val
lcbrooks Jul 22, 2022
350ea44
Change "LOCF" to "LVCF" where it's referring to last version carried …
lcbrooks Jul 22, 2022
ec1211b
Merge branch 'main' into km-compactify_rectify
lcbrooks Jul 24, 2022
bb8bebe
Fix epix_fill_through_version bug from unique-aliasing edge case
lcbrooks Jul 24, 2022
74cc3cf
Fill out tests for new epix_merge
lcbrooks Jul 24, 2022
2691294
Fix head -> utils::head
lcbrooks Jul 24, 2022
19322bc
Fix some undoc'd archive params, base::invisible links
lcbrooks Jul 24, 2022
dc8fc10
Merge in epix_slide quosure-passing fix + test
lcbrooks Jul 24, 2022
1738e00
Fix tail -> utils::tail in epix_merge
lcbrooks Jul 24, 2022
a7bf0b6
Update examples, vignettes to use current merge (but keeping dead? code)
lcbrooks Jul 24, 2022
22c0559
Fix compactify vignette rebuilding in `check()`
lcbrooks Jul 24, 2022
e26f6dd
Avoid some check() NOTEs from data.table dotdot prefix
lcbrooks Jul 24, 2022
adc367f
Remove improper and faulty tidyselect usage from group_by tests
lcbrooks Jul 25, 2022
b2bde0e
Make epix_slide tidyselect tests tougher (not just default grping)
lcbrooks Jul 25, 2022
8271a97
Change "LVCF" back to "LOCF", but with consistent intro text
lcbrooks Jul 27, 2022
155ea73
Rename `observed_versions_end[_conflict]` -> `versions_end[_conflict]`
lcbrooks Jul 27, 2022
a71c3fe
Rename versions_end_conflict -> sync, "stop" -> "forbid"
lcbrooks Jul 27, 2022
4c1f7c8
Merge branch 'main' into km-compactify_rectify
kenmawer Jul 27, 2022
2ddc3d5
Updated km-compactify_rectify whilst dealing with conflicts.
kenmawer Jul 27, 2022
c5eaf14
Empty commit.
kenmawer Jul 27, 2022
ef45cf1
Fixup merge
lcbrooks Jul 28, 2022
8bb37c4
Fixup formatting on merge fixup
lcbrooks Jul 28, 2022
ca37636
Merge branch 'main' into km-compactify_rectify
kenmawer Jul 28, 2022
174fecf
Changed `n`'s default to be consistent with the rest of the branch.
kenmawer Jul 28, 2022
4eb7f11
Updated missing n.
kenmawer Jul 28, 2022
c1c61e4
Repair compactify vignette median slide
lcbrooks Jul 29, 2022
bbd1c17
Sync compactify.Rmd text with code: 1000 iterations of filter
lcbrooks Jul 29, 2022
2a79c08
Fix incomplete change from "LVCF" back to "LOCF"
lcbrooks Jul 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ Suggests:
knitr,
outbreaks,
rmarkdown,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
waldo (>= 0.3.1),
withr
VignetteBuilder:
knitr
Remotes:
Expand All @@ -56,7 +58,7 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0
RoxygenNote: 7.2.1
Depends:
R (>= 2.10)
URL: https://cmu-delphi.github.io/epiprocess/
13 changes: 11 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ S3method(filter,epi_df)
S3method(group_by,epi_df)
S3method(group_modify,epi_df)
S3method(mutate,epi_df)
S3method(next_after,Date)
S3method(next_after,integer)
S3method(print,epi_df)
S3method(relocate,epi_df)
S3method(rename,epi_df)
Expand All @@ -19,6 +21,7 @@ S3method(summary,epi_df)
S3method(ungroup,epi_df)
S3method(unnest,epi_df)
export("%>%")
export(archive_cases_dv_subset)
export(arrange)
export(as_epi_archive)
export(as_epi_df)
Expand All @@ -38,19 +41,23 @@ export(group_modify)
export(growth_rate)
export(is_epi_archive)
export(is_epi_df)
export(max_version_with_row_in)
export(mutate)
export(new_epi_df)
export(next_after)
export(relocate)
export(rename)
export(slice)
export(ungroup)
export(unnest)
importFrom(R6,R6Class)
importFrom(data.table,":=")
importFrom(data.table,address)
importFrom(data.table,as.data.table)
importFrom(data.table,between)
importFrom(data.table,copy)
importFrom(data.table,key)
importFrom(data.table,merge.data.table)
importFrom(data.table,nafill)
importFrom(data.table,set)
importFrom(data.table,setkeyv)
importFrom(dplyr,arrange)
importFrom(dplyr,filter)
Expand All @@ -69,9 +76,11 @@ importFrom(rlang,"!!!")
importFrom(rlang,"!!")
importFrom(rlang,.data)
importFrom(rlang,.env)
importFrom(rlang,arg_match)
importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,is_quosure)
importFrom(rlang,quo_is_missing)
importFrom(rlang,sym)
importFrom(rlang,syms)
importFrom(stats,cor)
Expand Down
481 changes: 410 additions & 71 deletions R/archive.R

Large diffs are not rendered by default.

123 changes: 122 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,129 @@
#' * \href{https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/doctor-visits.html}{From the COVIDcast Doctor Visits API}: The signal `percent_cli` is taken directly from the API without changes.
#' * \href{https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/jhu-csse.html}{From the COVIDcast Epidata API}: `case_rate_7d_av` is taken directly from the JHU CSSE \href{https://github.com/CSSEGISandData/COVID-19}{COVID-19 GitHub repository} without changes. The 7-day average signals are computed by Delphi by calculating moving averages of the preceding 7 days, so the signal for June 7 is the average of the underlying data for June 1 through 7, inclusive.
#' * Furthermore, the data is a subset of the full dataset, the signal names slightly altered, and formatted into a tibble.
#'
#' @export
"archive_cases_dv_subset"

#' Detect whether `pkgload` is unregistering a package (with some unlikely false positives)
#'
#' More precisely, detects the presence of a call to an `unregister` or
#' `unregister_namespace` function from any package in the indicated part of the
#' function call stack.
#'
#' @param parent_n optional, single non-`NA` non-negative integer; how many
#' "parent"/"ancestor" calls should we skip inspecting? Default of `0L` will
#' check everything up to, but not including the call to this function. If
#' building wrappers or utilities around this function it may be useful to use
#' this default to ignore those wrappers, especially if they might trigger
#' false positives now or in some future version of this function with a looser
#' function name test.
#'
#' @return Boolean
#'
#' @noRd
some_package_is_being_unregistered = function(parent_n = 0L) {
calls = sys.calls()
# `calls` will include the call to this function; strip out this call plus
# `parent_n` additional requested calls to make it like we're reasoning about
# the desired call. This could prevent potential false positives from
# triggering if, in a later version, we decide to loosen the `call_name`
# checks below to something that would be `TRUE` for the name of this function
# or one of the undesired call ancestors.
calls_to_inspect = utils::head(calls, n = -(parent_n + 1L))
# Note that `utils::head(sys.calls(), n=-1L)` isn't equivalent, due to lazy
# argument evaluation. Note that copy-pasting the body of this function
# without this `utils::head` operation isn't always equivalent to calling it;
# e.g., within the `value` argument of a package-level `delayedAssign`,
# `sys.calls()` will return `NULL` is some or all cases, including when its
# evaluation has been triggered via `unregister`.
simple_call_names = purrr::map_chr(calls_to_inspect, function(call) {
maybe_simple_call_name = rlang::call_name(call)
if (is.null(maybe_simple_call_name)) NA_character_ else maybe_simple_call_name
})
# `pkgload::unregister` is an (the?) exported function that forces
# package-level promises, while `pkgload:::unregister_namespace` is the
# internal function that does this package-level promise. Check for both just
# in case there's another exported function that calls `unregister_namespace`
# or other `pkgload` versions don't use the `unregister_namespace` internal.
# (Note that `NA_character_ %in% <table not containing NA>` is `FALSE` rather
# than `NA`, giving the desired semantics and avoiding potential `NA`s in the
# argument to `any`.)
any(simple_call_names %in% c("unregister", "unregister_namespace"))
}

#' [`base::delayedAssign`] with [`pkgload::unregister`] awareness, injection support
#'
#' Provides better feedback on errors during promise evaluation while a package
#' is being unregistered, to help package developers escape from a situation
#' where a buggy promise prevents package reloading. Also provide `rlang`
#' injection support (like [`rlang::env_bind_lazy`]). The call stack will look
#' different than when using `delayedAssign` directly.
#'
#' @noRd
delayed_assign_with_unregister_awareness = function(x, value,
eval.env = rlang::caller_env(),
assign.env = rlang::caller_env()) {
value_quosure = rlang::as_quosure(rlang::enexpr(value), eval.env)
this_env = environment()
delayedAssign(x, eval.env = this_env, assign.env = assign.env, value = {
if (some_package_is_being_unregistered()) {
withCallingHandlers(
# `rlang::eval_tidy(value_quosure)` is shorter and would sort of work,
# but doesn't give the same `ls`, `rm`, and top-level `<-` behavior as
# we'd have with `delayedAssign`; it doesn't seem to actually evaluate
# quosure's expr in the quosure's env. Using `rlang::eval_bare` instead
# seems to do the trick. (We also could have just used a `value_expr`
# and `eval.env` together rather than introducing `value_quosure` at
# all.)
rlang::eval_bare(rlang::quo_get_expr(value_quosure), rlang::quo_get_env(value_quosure)),
error = function(err) {
Abort(paste("An error was raised while attempting to evaluate a promise",
"(prepared with `delayed_assign_with_unregister_awareness`)",
"while an `unregister` or `unregister_namespace` call",
"was being evaluated.",
"This can happen, for example, when `devtools::load_all`",
"reloads a package that contains a buggy promise,",
"because reloading can cause old package-level promises to",
"be forced via `pkgload::unregister` and",
"`pkgload:::unregister_namespace`, due to",
"https://github.com/r-lib/pkgload/pull/157.",
"If this is the current situation, you might be able to",
"be successfully reload the package again after",
"`unloadNamespace`-ing it (but this situation will",
"keep re-occurring every other `devtools::load`",
"and every `devtools:document` until the bug or situation",
"generating the promise's error has been resolved)."
),
class = "epiprocess__promise_evaluation_error_during_unregister",
parent = err)
})
} else {
rlang::eval_bare(rlang::quo_get_expr(value_quosure), rlang::quo_get_env(value_quosure))
}
})
}

# Like normal data objects, set `archive_cases_dv_subset` up as a promise, so it
# doesn't take unnecessary space before it's evaluated. This also avoids a need
# for @include tags. However, this pattern will use unnecessary space after this
# promise is evaluated, because `as_epi_archive` clones `archive_cases_dv_subset_dt`
# and `archive_cases_dv_subset_dt` will stick around along with `archive_cases_dv_subset`
# after they have been evaluated. We may want to add an option to avoid cloning
# in `as_epi_archive` and make use of it here. But we may also want to change
# this into an active binding that clones every time, unless we can hide the
# `DT` field from the user (make it non-`public` in general) or make it
# read-only (in this specific case), so that the user cannot modify the `DT`
# here and potentially mess up examples that they refer to later on.
#
# During development, note that reloading the package and re-evaluating this
# promise should prepare the archive from the DT using any changes that have
# been made to `as_epi_archive`; however, if earlier, any field of
# `archive_cases_dv_subset` was modified using `<-`, a global environment
# binding may have been created with the same name as the package promise, and
# this binding will stick around even when the package is reloaded, and will
# need to be `rm`-d to easily access the refreshed package promise.
delayed_assign_with_unregister_awareness("archive_cases_dv_subset", as_epi_archive(archive_cases_dv_subset_dt, compactify=FALSE))

#' Subset of JHU daily cases from California and Florida
#'
Expand Down Expand Up @@ -120,4 +241,4 @@
#' Modifications:
#' * \href{https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/jhu-csse.html}{From the COVIDcast Epidata API}: These signals are taken directly from the JHU CSSE \href{https://github.com/CSSEGISandData/COVID-19}{COVID-19 GitHub repository} without changes. The 7-day average signals are computed by Delphi by calculating moving averages of the preceding 7 days, so the signal for June 7 is the average of the underlying data for June 1 through 7, inclusive.
#' * Furthermore, the data has been limited to a very small number of rows, the signal names slightly altered, and formatted into a tibble.
"jhu_csse_county_level_subset"
"jhu_csse_county_level_subset"
Loading