-
Notifications
You must be signed in to change notification settings - Fork 9
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
epi_df
argument refactoring
#460
base: dev
Are you sure you want to change the base?
Changes from all commits
1ab1095
0f0fe40
ec23ec7
a30d41e
441bdae
c8b73ce
b5e9d20
7af380b
b7414a8
e144803
924e5ee
5825181
33ef7c7
536d7d7
243c20e
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 |
---|---|---|
|
@@ -95,7 +95,7 @@ NULL | |
#' | ||
#' @export | ||
new_epi_df <- function(x = tibble::tibble(), geo_type, time_type, as_of, | ||
additional_metadata = list(), ...) { | ||
additional_metadata = list()) { | ||
assert_data_frame(x) | ||
assert_list(additional_metadata) | ||
|
||
|
@@ -249,25 +249,37 @@ as_epi_df.epi_df <- function(x, ...) { | |
|
||
#' @method as_epi_df tbl_df | ||
#' @describeIn as_epi_df The input tibble `x` must contain the columns | ||
#' `geo_value` and `time_value`. All other columns will be preserved as is, | ||
#' and treated as measured variables. If `as_of` is missing, then the function | ||
#' will try to guess it from an `as_of`, `issue`, or `version` column of `x` | ||
#' (if any of these are present), or from as an `as_of` field in its metadata | ||
#' (stored in its attributes); if this fails, then the current day-time will | ||
#' be used. | ||
#' `geo_value` and `time_value`, or column names that uniquely map onto these | ||
#' (e.g. `date` or `province`). Alternatively, you can specify the conversion | ||
#' explicitly (`time_value = someWeirdColumnName`). All other columns not | ||
#' specified as `other_keys` will be preserved as is, and treated as measured | ||
#' variables. | ||
#' | ||
#' If `as_of` is missing, then the function will try to guess it from an | ||
#' `as_of`, `issue`, or `version` column of `x` (if any of these are present), | ||
#' or from as an `as_of` field in its metadata (stored in its attributes); if | ||
#' this fails, then the current day-time will be used. | ||
#' @importFrom rlang .data | ||
#' @importFrom tidyselect any_of | ||
#' @importFrom cli cli_inform | ||
#' @export | ||
as_epi_df.tbl_df <- function(x, geo_type, time_type, as_of, | ||
additional_metadata = list(), ...) { | ||
additional_metadata = list(), | ||
...) { | ||
dsweber2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# possible standard substitutions for time_value | ||
x <- rename(x, ...) | ||
x <- guess_column_name(x, "time_value", time_column_names()) | ||
x <- guess_column_name(x, "geo_value", geo_column_names()) | ||
if (!test_subset(c("geo_value", "time_value"), names(x))) { | ||
cli_abort( | ||
"Columns `geo_value` and `time_value` must be present in `x`." | ||
"Either columns `geo_value` and `time_value` must be present in `x`, or related columns (see the internal | ||
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. question: do we need the same type of check and error in the 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. it's already there? The most recent commit includes a wording change to match this though. |
||
functions `guess_time_column_name()` and/or `guess_geo_column_name()` for a complete list)." | ||
) | ||
} | ||
|
||
new_epi_df( | ||
x, geo_type, time_type, as_of, | ||
additional_metadata, ... | ||
additional_metadata | ||
) | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
question: do we need to do a
tryCatch
here, too?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.
The error in this case is
which I think is more obvious what went wrong. For the other rename, it's buried a little deeper why the names are redundant, so I wanted to give some context