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

nest() generic might error for unnamed dots #1134

Closed
mgirlich opened this issue Jul 1, 2021 · 1 comment · Fixed by #1204
Closed

nest() generic might error for unnamed dots #1134

mgirlich opened this issue Jul 1, 2021 · 1 comment · Fixed by #1204
Labels
feature a feature request or enhancement nesting 🐦 nesting, chopping, and packing

Comments

@mgirlich
Copy link
Contributor

mgirlich commented Jul 1, 2021

Before calling the method corresponding to the class the nest() generic tries to name any unnamed dots. This doesn't work for lazy tibbles:

library(dtplyr)
library(tidyr)

dt <- lazy_dt(tibble(x = c(1, 2, 1), y = c("a", "a", "b")))
dt %>% nest(y)
#> Error: `x` must be a vector, not a <dtplyr_step_first/dtplyr_step> object.

Created on 2021-07-01 by the reprex package (v2.0.0)

The issue is the following line

col_names <- names(tidyselect::eval_select(expr(c(...)), .data))

The question is how to handle this?

@hadley hadley added feature a feature request or enhancement rectangling 🗄️ converting deeply nested lists into tidy data frames labels Aug 23, 2021
@DavisVaughan
Copy link
Member

DavisVaughan commented Oct 27, 2021

I have a feeling we can resolve this by avoiding eval_select() at this point altogether. I think we just need to do something like expr(c(!!!cols)), and we can use as_label() on that to create a decent message.

tidyr/R/nest.R

Lines 124 to 136 in 89b409d

if (any(names2(cols) == "")) {
col_names <- names(tidyselect::eval_select(expr(c(...)), .data))
cols_expr <- expr(c(!!!syms(col_names)))
.key <- if (missing(.key)) "data" else as.character(ensym(.key))
cols <- quos(!!.key := !!cols_expr)
warn(paste0(
"All elements of `...` must be named.\n",
"Did you want `", .key, " = ", expr_text(cols_expr), "`?"
))
return(nest(.data, !!!cols))
}

I'm not sure that would fix the problem for dtplyr though. Eventually in the dtplyr method for nest() you will have to call eval_select() and you'll need access to the column names of the lazy data.table, and I don't think there is any way to access that right now Oh I see there is dtplyr:::simulate_vars() so maybe you can work with that an the eventual allow_predicate = FALSE in tidy select.

@DavisVaughan DavisVaughan added nesting 🐦 nesting, chopping, and packing and removed rectangling 🗄️ converting deeply nested lists into tidy data frames labels Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement nesting 🐦 nesting, chopping, and packing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants