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

summarize_all() throws error when using tilde notation #134

Closed
krlmlr opened this issue Jul 25, 2018 · 3 comments
Closed

summarize_all() throws error when using tilde notation #134

krlmlr opened this issue Jul 25, 2018 · 3 comments
Labels
feature verb trans 🤖
Milestone

Comments

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Jul 25, 2018

I'm not sure if this will be fixed with tidyverse/dplyr#3433. Also, I don't understand why the second example gives a warning. Thanks @Romanik!

library(tidyverse)
dbplyr::memdb_frame(a = 1, b = 2) %>% 
  summarize_all(~mean(.))
#> Error in mean(.): object 'a' not found
dbplyr::memdb_frame(a = 1, b = 2) %>% 
  summarize_all(mean)
#> Warning: Missing values are always removed in SQL.
#> Use `AVG(x, na.rm = TRUE)` to silence this warning

#> Warning: Missing values are always removed in SQL.
#> Use `AVG(x, na.rm = TRUE)` to silence this warning
#> # Source:   lazy query [?? x 2]
#> # Database: sqlite 3.22.0 [:memory:]
#>       a     b
#>   <dbl> <dbl>
#> 1     1     2
dbplyr::memdb_frame(a = 1, b = 2) %>% 
  summarize_if(funs(is.numeric), ~mean(.))
#> Applying predicate on the first 100 rows
#> Error in mean(.): object 'a' not found

Created on 2018-07-25 by the reprex package (v0.2.0).

@karldw

This comment has been minimized.

@hadley
Copy link
Member

@hadley hadley commented Jan 2, 2019

Mild reprex tweaking

library(dplyr, warn.conflicts = FALSE)
mf <- dbplyr::memdb_frame(a = 1, b = 2)

# WORKS
mf %>% summarize_all(mean, na.rm = TRUE)
#> # Source:   lazy query [?? x 2]
#> # Database: sqlite 3.22.0 [:memory:]
#>       a     b
#>   <dbl> <dbl>
#> 1     1     2

# FAILS
mf %>% summarize_all(~mean(.))
#> Error in mean(.): object 'a' not found
mf %>% summarize_all(list(mean))
#> Error in (function (x, ...) : object 'a' not found

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

@hadley hadley added feature verb trans 🤖 labels Jan 2, 2019
@hadley hadley added this to the v1.4.0 milestone Jan 9, 2019
@hadley
Copy link
Member

@hadley hadley commented Feb 6, 2019

summarise_all() creates a list of inlined functions so an even more focussed reprex is this:

library(dbplyr)

partial_eval(rlang::expr(mean(x)), vars = "x")
#> mean(x)
partial_eval(rlang::expr((!!mean)(x)), vars = "x")
#> Error in (function (x, ...) : object 'x' not found

Created on 2019-02-06 by the reprex package (v0.2.1.9000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature verb trans 🤖
Projects
None yet
Development

No branches or pull requests

3 participants