-
Notifications
You must be signed in to change notification settings - Fork 58
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
Implements drop_na() #194
Implements drop_na() #194
Conversation
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.
Looks good, thanks!
NEWS.md
Outdated
with `pivot_wider()` (@markfairbanks, #189). | ||
with: | ||
|
||
* `drop_na()` (@markfairbanks, #194) |
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.
dtplyr just made it to CRAN so once you merge/rebase, you'll need to move this to a new bullet in the dev version.
R/step-call.R
Outdated
drop_na(data, ...) | ||
} | ||
|
||
globalVariables("drop_na") |
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.
You can instead add to dt_funs
in tidyeval.R
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.
Isn't dt_funs
just for data.table functions? From what I could tell na.omit()
doesn't need to be added to dt_funs
since data.table is just exporting a method for stats::na.omit()
.
The globalVariables("drop_na")
was to pass R CMD check - it throws this error otherwise:
drop_na.data.table: no visible global function definition for ‘drop_na’
Undefined global functions or variables:
drop_na
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.
Oh sorry, I totally misinterpreted the problem. You should use tidyr::drop_na()
in the drop_na
method.
tests/testthat/test-step-call.R
Outdated
df <- lazy_dt(tibble(x = c(1, 2, NA), y = c("a", NA, "b")), "DT") | ||
exp <- tibble(x = c(1), y = c("a")) | ||
step <- drop_na(df) | ||
res <- as_tibble(step) | ||
expect_equal(show_query(step), expr(na.omit(DT))) | ||
expect_equal(res, exp) |
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 think this is a little easier to follow:
df <- lazy_dt(tibble(x = c(1, 2, NA), y = c("a", NA, "b")), "DT") | |
exp <- tibble(x = c(1), y = c("a")) | |
step <- drop_na(df) | |
res <- as_tibble(step) | |
expect_equal(show_query(step), expr(na.omit(DT))) | |
expect_equal(res, exp) | |
tb <- tibble(x = c(1, 2, NA), y = c("a", NA, "b") | |
dt <- drop_na(lazy_dt(tb, "DT")) | |
expect_equal(show_query(dt), expr(na.omit(DT))) | |
expect_equal(as_tibble(step), tb[1, ]) |
tests/testthat/test-step-call.R
Outdated
expect_equal(res, exp) | ||
}) | ||
|
||
test_that("groups are preserved", { |
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.
Is it necessary to test this? It's step_call()
that takes care of this, not your code.
tests/testthat/test-step-call.R
Outdated
expect_equal(dplyr::group_vars(res), dplyr::group_vars(gexp)) | ||
}) | ||
|
||
test_that("empty call drops every row", { |
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.
Duplicate of first test?
tests/testthat/test-step-call.R
Outdated
expect_error(collect(drop_na(df, !! list()))) | ||
expect_error(collect(drop_na(df, "z"))) |
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.
These should be expect_snapshot(error = TRUE, ...)
so we can see the precise errors
tests/testthat/test-step-call.R
Outdated
test_that("single variable data.frame doesn't lose dimension", { | ||
df <- lazy_dt(data.frame(x = c(1, 2, NA))) | ||
res <- as.data.frame(drop_na(df, "x")) | ||
exp <- data.frame(x = c(1, 2)) | ||
expect_equal(res, exp) | ||
}) | ||
|
||
test_that("preserves attributes", { | ||
df <- lazy_dt(tibble(x = structure(c(1, NA), attr = "!"))) | ||
rs <- collect(drop_na(df)) | ||
|
||
expect_equal(rs$x, structure(1, attr = "!")) | ||
}) |
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 think these are data.frame specific so can be dropped.
Merge remote-tracking branch 'upstream/master' into drop_na # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
tests/testthat/test-step-call.R
Outdated
test_that("errors are raised", { | ||
tb <- tibble(x = c(1, 2, NA), y = c("a", NA, "b")) | ||
dt <- lazy_dt(tb, "DT") | ||
expect_snapshot(collect(drop_na(dt, !! list())), error = TRUE) |
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 sure what this is supposed to test, and it looks like the !!
is being evaluated too early. So I suggest just dropping it.
All set for review |
Thanks! |
No description provided.