Skip to content

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 19 commits into from
Jul 8, 2022

Conversation

rachlobay
Copy link
Collaborator

As per issue 96 head.epi_df and tail.epi_df to keep the epi_df class when they are used. Note the tests for this in test-methods-epi_df.R

@rachlobay rachlobay linked an issue Jun 16, 2022 that may be closed by this pull request
@brookslogan
Copy link
Contributor

The comments above are very minor. This PR could be merged to address #96 without any changes.

@dajmcdon
Copy link
Contributor

@rachlobay I spent a bit of time looking into this, and I think we're doing this the wrong way (my fault). head() actually calls utils:::head.matrix() eventually, which uses [.tbl_df. So rather than implementing head.epi_df() we should actually be implementing [.epi_df. Those changes will then propagate to a call to head() or tail() as well as keeping the class if someone does some_epi_df[1:5, ].

I think we want it to drop the class and the metadata if they do column selection: some_epi_df[ ,1:2] should just go to a tbl_df.

Good examples are in tibble or probably even better tsibble. I suspect that we essentially need most of the code in the tSibble link.

@rachlobay
Copy link
Collaborator Author

Ok. I have removed head.epi_df and tail.epi_df and instead implemented [.epi_df based on the tsibble [.tbl_ts. The tests are passing for head() and tail(). @dajmcdon please have a look at the [.epi_df when you can and let me know if you would like me to make any changes.

Copy link
Contributor

@dajmcdon dajmcdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are a few additional tests that we need here, otherwise, the rest is linting.

att_x = attributes(x)
new_epi_df(tibble::as_tibble(res), geo_type = att_x$metadata$geo_type,
time_type = att_x$metadata$time_type, as_of = att_x$metadata$as_of,
additional_metadata =
Copy link
Contributor

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.

@rachlobay rachlobay requested a review from dajmcdon July 1, 2022 19:04
@brookslogan
Copy link
Contributor

brookslogan commented Jul 7, 2022

Some notes:

  • Above test failures are related to the additional_metadata; at least some [might be] due to a missing[/extra] $additional_metadata in the tests.
  • The additional_metadata can be set directly in as_epi_df; see pkgload::dev_help("as_epi_df"). [EDIT: or not... I just tried this out and the additional_metadata are not forwarded; list() is passed to new_epi_df instead. Maybe a function signature copy-paste bug.]
  • Either additional_key_name and "additional_key_type" should be changed to other_keys and "<some column that acts as part of the key in addition to geo and time values>" or turned into something without "key" in the name. E.g., source_url -> "https://example.com/data.csv" or something like that.

@rachlobay
Copy link
Collaborator Author

@brookslogan Thanks for the comments! To let you know, I ended up fixing the bug that you spotted in as_epi_df() and used that to add the other key (as in %>% as_epi_df(additional_metadata = c(other_keys = "indicator_var"))).

@rachlobay rachlobay merged commit a9697b7 into main Jul 8, 2022
@rachlobay rachlobay deleted the head-tail-keep-class branch August 18, 2022 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

head() and tail() drop the class
3 participants