-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow empty annotations. #3320
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
clauswilke
merged 5 commits into
tidyverse:master
from
wilkelab:issue-3317-empty-dataframe
May 16, 2019
Merged
Allow empty annotations. #3320
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3f6e315
allow empty annotations. fixes #3317
clauswilke cee085f
fix corner case where all annotation parameters have length 1
clauswilke cfd4962
add unit tests, simplify code; closes #3314
clauswilke 4ff8243
improve comments
clauswilke b313162
simplify code calculating number of rows in annotation data frame
clauswilke 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
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
context("Performance related alternatives") | ||
|
||
# ******************** | ||
# modify_list() | ||
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. Can you please use our standard sectioning convention?
|
||
|
||
testlist <- list( | ||
a = 5.5, | ||
b = "x", | ||
|
@@ -32,3 +35,35 @@ test_that("modify_list erases null elements", { | |
expect_null(res$c) | ||
expect_named(res, c('a', 'b', 'd')) | ||
}) | ||
|
||
|
||
# ******************** | ||
# new_data_frame() | ||
|
||
test_that("new_data_frame handles zero-length inputs", { | ||
# zero-length input creates zero-length data frame | ||
d <- new_data_frame(list(x = numeric(0), y = numeric(0))) | ||
expect_equal(nrow(d), 0L) | ||
|
||
# constants are ignored in the context of zero-length input | ||
d <- new_data_frame(list(x = numeric(0), y = numeric(0), z = 1)) | ||
expect_equal(nrow(d), 0L) | ||
|
||
# vectors of length > 1 don't mix with zero-length input | ||
expect_error( | ||
new_data_frame(list(x = numeric(0), y = numeric(0), z = 1, a = c(1, 2))), | ||
"Elements must equal the number of rows or 1" | ||
) | ||
|
||
# explicit recycling doesn't work with zero-length input | ||
expect_error( | ||
new_data_frame(list(x = numeric(0), z = 1), n = 5), | ||
"Elements must equal the number of rows or 1" | ||
) | ||
# but it works without | ||
d <- new_data_frame(list(x = 1, y = "a"), n = 5) | ||
expect_equal(nrow(d), 5L) | ||
expect_identical(d$x, rep(1, 5L)) | ||
expect_identical(d$y, rep("a", 5L)) | ||
|
||
}) |
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.
Why does it fail?
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.
Maybe a poorly formulated comment. The purpose of line 49 is to find the unique lengths that are not
1L
. However, iflengths == c(1L)
, then we getn <- numeric(0)
in line 49, and we needn <- 1L
in this case.