-
Notifications
You must be signed in to change notification settings - Fork 2
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
Adds ys_prune #97
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e34bd68
adds ys_prune
kylebaron a2ae708
change tense
kylebaron 451de6b
fix test
kylebaron 5ac9b07
fix typo; added non-columns to test
kylebaron 8952085
fix column order; enhance test
kylebaron dad5d81
roll back expectation on final result for col order
kylebaron 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,34 @@ | ||
library(yspec) | ||
library(testthat) | ||
|
||
context("test-prune") | ||
|
||
test_that("ys_prune selects available columns", { | ||
data <- ys_help$data() | ||
spec <- ys_help$spec() | ||
data$STUDY <- NULL | ||
data$TAD <- NULL | ||
data$FOO <- 1 | ||
data$BAR <- 2 | ||
set.seed(1103) | ||
data <- data[, sample(names(data)), drop = FALSE] | ||
ans <- ys_prune(data, spec) | ||
spec2 <- ys_select(spec, -STUDY, -TAD) | ||
expect_identical(class(data), class(ans)) | ||
expect_true(is.data.frame(ans)) | ||
expect_equal(names(ans), names(spec2)) | ||
expect_error( | ||
ys_prune(data.frame(a = 2), spec), | ||
regexp = "there are no names common between" | ||
) | ||
expect_message( | ||
ans <- ys_prune(data, spec, report = TRUE), | ||
regexp = "Column not found: STUDY", | ||
all = FALSE, fixed = TRUE | ||
) | ||
expect_message( | ||
ans <- ys_prune(data, spec, report = TRUE), | ||
regexp = "Column not found: TAD", | ||
all = FALSE, fixed = TRUE | ||
) | ||
}) |
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.
@kylebaron
should this test have a data frame with more columns than the spec?
For example
The current test has the reverse, and therefore:
names(ys_prune(data, spec)) == names(data)
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.
Yes; I was intending fewer columns. Can add more columns 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.
Added two columns matching nothing.
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.
@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?
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.
Thanks, @andersone1 ; yes, there was something wrong in the logic for matching / ordering the names.
ys_prune
data
in the testThanks!
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 reverted that one expectation; I do think we want this to be the check:
The names in the final answer are identical (including order) to the names in the spec, minus the columns that we dropped.