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

dbplyr: n_distinct translation does not handle na.rm #133

Closed
move bot opened this issue Jul 21, 2018 · 0 comments

Comments

@move
Copy link

@move move bot commented Jul 21, 2018

@colearendt commented on Jul 20, 2018, 10:33 AM UTC:

Definition of n_distinct:

function (..., na.rm = FALSE) 
{
    n_distinct_multi(list(...), na.rm)
}
<environment: namespace:dplyr>

And the translation:

  n_distinct = function(...) {
    vars <- sql_vector(list(...), parens = FALSE, collapse = ", ")
    build_sql("COUNT(DISTINCT ", vars, ")")
  }

n_distinct = function(...) {
vars <- sql_vector(list(...), parens = FALSE, collapse = ", ")
build_sql("COUNT(DISTINCT ", vars, ")")
}
)

n_distinct = function(...) {
vars <- sql_vector(list(...), parens = FALSE, collapse = ", ")
win_over(build_sql("COUNT(DISTINCT ", vars, ")"), win_current_group())
},

Which results in:

pd %>% summarise(n_distinct(fld_integer, na.rm = TRUE)) %>% show_query()
#<SQL>
#SELECT COUNT(DISTINCT "fld_integer", TRUE AS "na.rm") AS "n_distinct(fld_integer, na.rm = TRUE)"
#FROM "testdata"

na.rm should not be included in the splicing.

This issue was moved by krlmlr from tidyverse/dplyr#3720.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.