Skip to content

dplyr::n() does not work on databases #197

Closed

Description

@JohnMount

The dplyr::n() notation suggested in https://github.com/tidyverse/dplyr/blob/master/NEWS.md#breaking-changes does not work on database handles.

packageVersion("dplyr")
#> [1] '0.7.8'

# works
dplyr::summarize(data.frame(x = 1), count = dplyr::n())
#>   count
#> 1     1

# fails
db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
t <- dplyr::copy_to(db, data.frame(x = 1), "d")
dplyr::summarize(t, count = dplyr::n())
#> Error: This function should not be called directly

Created on 2018-12-31 by the reprex package (v0.2.1)

See also tidyverse/dplyr#4062 .

Activity

  1. transferred this issue fromtidyverse/dplyron Dec 31, 2018
  2. hadley commented on Dec 31, 2018

    @hadley
    Member

    Moved to dbplyr since that is where the problem lies.

  3. added
    bugan unexpected problem or unintended behavior
    on Jan 2, 2019
  4. added this to the v1.2.2 milestone on Jan 2, 2019
  5. hadley commented on Jan 2, 2019

    @hadley
    Member

    Minimal reprex:

    mf <- dbplyr::memdb_frame(x = 1:10)
    dplyr::summarise(mf, n = dplyr::n())
    #> Error: This function should not be called directly
    #> Backtrace:
    #>     █
    #>  1. ├─dplyr::summarise(mf, n = dplyr::n())
    #>  2. ├─dbplyr:::summarise.tbl_lazy(mf, n = dplyr::n())
    #>  3. │ └─dbplyr::partial_eval(dots, vars = op_vars(.data))
    #>  4. │   ├─rlang::switch_type(...)
    #>  5. │   └─dbplyr:::map(call, partial_eval, vars = vars, env = env)
    #>  6. │     └─base::lapply(.x, .f, ...)
    #>  7. │       └─dbplyr:::FUN(X[[i]], ...)
    #>  8. │         ├─rlang::switch_type(...)
    #>  9. │         └─dbplyr::partial_eval(f_rhs(call), vars, f_env(call))
    #> 10. │           ├─rlang::switch_type(...)
    #> 11. │           └─dbplyr:::lang_partial_eval(call, vars, env)
    #> 12. │             ├─rlang::switch_lang(...)
    #> 13. │             └─rlang::eval_bare(call, env)
    #> 14. └─dplyr::n()

    Created on 2019-01-02 by the reprex package (v0.2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions