-
Notifications
You must be signed in to change notification settings - Fork 8
Keep the epi_df
class when head and tail are used
#105
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a37a462
Modified head and tail functions to keep epi_df class and added some …
df103d5
Make sure epi_df was unchanged from original
8a2f694
Simplified code some more and renamed tib
5aaac8d
Commented why set-up NextMethod() that way
1c8b565
Added comment
439b638
commented out head and tail
4bf9ab0
Removed head and tail
62c389a
Added `[.epi_df` mehtod and removed head and tail fun for epi_df
95bd401
Imported vctrs
179649e
Added some changes as per comments
9c59ee9
Added additional key
5ae2e4b
Change back to how it was before.
88162eb
Change file back to how it was before...
5bb43de
Updating all files to match main branch
a5d55b6
Added tests as per reccomendations on comments
ead3ed0
Removed an unnecessary line
5b4d6d1
Removed empty line
740094e
Updated test additional_metadata & the passing of that into as_epi_df()
cd5aa48
Removed unnecessary epiprocess
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ Imports: | |
tidyr, | ||
tidyselect, | ||
tsibble, | ||
utils | ||
utils, | ||
vctrs | ||
Suggests: | ||
covidcast, | ||
delphi.epidata, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
toy_epi_df <- tibble::tibble( | ||
x = 1:10, | ||
y = 1:10, | ||
time_value = rep(seq( | ||
as.Date("2020-01-01"), | ||
by = 1, | ||
length.out = 5 | ||
), times = 2), | ||
geo_value = rep(c("ca", "hi"), each = 5), | ||
indicator_var = as.factor(rep(1:2, times = 5)), | ||
) %>% as_epi_df(additional_metadata = c(other_keys = "indicator_var")) | ||
|
||
att_toy = attr(toy_epi_df, "metadata") | ||
|
||
test_that("head and tail do not drop the epi_df class", { | ||
att_head = attr(head(toy_epi_df), "metadata") | ||
att_tail = attr(tail(toy_epi_df), "metadata") | ||
|
||
rachlobay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect_true(is_epi_df(head(toy_epi_df))) | ||
expect_true(is_epi_df(tail(toy_epi_df))) | ||
expect_identical(att_head$geo_type, att_toy$geo_type) | ||
expect_identical(att_head$time_type, att_toy$time_type) | ||
expect_identical(att_head$as_of, att_toy$as_of) | ||
expect_identical(att_head$other_keys, att_toy$other_keys) | ||
expect_identical(att_tail$geo_type, att_toy$geo_type) | ||
expect_identical(att_tail$time_type, att_toy$time_type) | ||
expect_identical(att_tail$as_of, att_toy$as_of) | ||
expect_identical(att_tail$other_keys, att_toy$other_keys) | ||
}) | ||
|
||
|
||
test_that("subsetting drops or does not drop the epi_df class appropriately", { | ||
|
||
# Row subset - should be epi_df | ||
row_subset = toy_epi_df[1:2, ] | ||
att_row_subset = attr(row_subset, "metadata") | ||
|
||
expect_true(is_epi_df(row_subset)) | ||
expect_equal(nrow(row_subset), 2L) | ||
expect_equal(ncol(row_subset), 5L) | ||
expect_identical(att_row_subset$geo_type, att_toy$geo_type) | ||
expect_identical(att_row_subset$time_type, att_toy$time_type) | ||
expect_identical(att_row_subset$as_of, att_toy$as_of) | ||
expect_identical(att_row_subset$other_keys, att_toy$other_keys) | ||
|
||
# Col subset - shouldn't be an epi_df | ||
col_subset = toy_epi_df[, 2:3] | ||
|
||
expect_false(is_epi_df(col_subset)) | ||
expect_true(tibble::is_tibble(col_subset)) | ||
expect_equal(nrow(col_subset), 10L) | ||
expect_equal(ncol(col_subset), 2L) | ||
|
||
# Row and col single value - shouldn't be an epi_df | ||
row_col_subset1 = toy_epi_df[1,2] | ||
expect_false(is_epi_df(row_col_subset1)) | ||
expect_true(tibble::is_tibble(row_col_subset1)) | ||
expect_equal(nrow(row_col_subset1), 1L) | ||
expect_equal(ncol(row_col_subset1), 1L) | ||
|
||
# Row and col subset that contains geo_value and time_value - should be epi_df | ||
row_col_subset2 = toy_epi_df[2:3,1:3] | ||
att_row_col_subset2 = attr(row_col_subset2, "metadata") | ||
|
||
expect_true(is_epi_df(row_col_subset2)) | ||
expect_equal(nrow(row_col_subset2), 2L) | ||
expect_equal(ncol(row_col_subset2), 3L) | ||
expect_identical(att_row_col_subset2$geo_type, att_toy$geo_type) | ||
expect_identical(att_row_col_subset2$time_type, att_toy$time_type) | ||
expect_identical(att_row_col_subset2$as_of, att_toy$as_of) | ||
expect_identical(att_row_col_subset2$other_keys, att_toy$other_keys) | ||
|
||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not positive, but I suspect that this doesn't actually work. This is just giving you the names without the values.
I think you can safely do
additional_metadata = att_x$additional_metadata
but you should probably add a test to check that it works.