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

Adds ys_prune #97

Merged
merged 6 commits into from
Jan 3, 2022
Merged

Adds ys_prune #97

merged 6 commits into from
Jan 3, 2022

Conversation

kylebaron
Copy link
Contributor

Summary

  • Select any column from a data frame that appears in the spec object
  • Column order of the result is same as order in spec
  • Optionally report columns in spec that aren't in data
  • Error if no columns are in common between data and spec

@kylebaron kylebaron requested a review from andersone1 December 21, 2021 19:38
spec <- ys_help$spec()
data$STUDY <- NULL
data$TAD <- NULL
ans <- ys_prune(data, spec)

Choose a reason for hiding this comment

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

@kylebaron

should this test have a data frame with more columns than the spec?

For example

  • data has columns: A, B, C
  • spec has columns: A, B

The current test has the reverse, and therefore:

names(ys_prune(data, spec)) == names(data)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes; I was intending fewer columns. Can add more columns too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added two columns matching nothing.

Choose a reason for hiding this comment

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

@kylebaron

One other question - if I add:

data <- data[, rev(names(data)), drop = FALSE]

after line 12 (data$BAR <- 2) but before line 13 (ans <- ys_prune(data, spec))), the test then fails.

Is this OK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @andersone1 ; yes, there was something wrong in the logic for matching / ordering the names.

  • Fixed the logic in ys_prune
  • Randomized the names in data in the test
  • Added expectations for reporting columns not there

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted that one expectation; I do think we want this to be the check:

  expect_equal(names(ans), names(spec2))

The names in the final answer are identical (including order) to the names in the spec, minus the columns that we dropped.

@kylebaron kylebaron requested a review from andersone1 January 2, 2022 18:57
@kylebaron kylebaron merged commit b25a9c6 into develop Jan 3, 2022
@kylebaron kylebaron deleted the feature/ys_prune branch January 3, 2022 16:53
@kylebaron kylebaron linked an issue Jan 6, 2022 that may be closed by this pull request
@kylebaron kylebaron mentioned this pull request Mar 16, 2022
2 tasks
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.

Function to select common columns between data and spec
2 participants