Skip to content

Should quos_auto_name() use quo_name()? #573

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

Closed
lionel- opened this issue Aug 14, 2018 · 2 comments
Closed

Should quos_auto_name() use quo_name()? #573

lionel- opened this issue Aug 14, 2018 · 2 comments

Comments

@lionel-
Copy link
Member

lionel- commented Aug 14, 2018

And should expr_name() deparse any kind of object?

This is about suboptimal error messages like:

grouped_mean <- function(data, summary_var, ...) {
  summary_var <- enquo(summary_var)
  group_vars <- enquos(...)

  data %>%
    group_by(!!group_vars)
}

grouped_mean(mtcars, disp, cyl, am)
#> Error in mutate_impl(.data, dots) :
#>   Column `structure(list(~cyl, ~am), .Names = c("", ""), class = "quosures")` must be length 32 (the number of rows) or one, not 2

Caused by quos_auto_name() that uses expr_text()

x <- quos(cyl, am)
quos_auto_name(quos(!!x))
#> $`structure(list(~cyl, ~am), class = "quosures", .Names = c("", \n""))`
#> <quosure>
#>   expr: ^<S3: quosures>
#>   env:  empty

expr_text(x)
#> [1] "structure(list(~cyl, ~am), class = \"quosures\", .Names = c(\"\", \n\"\"))"

It doesn't seem to make sense to use a multi-line deparser to give default names to expressions? Then we should use quo_name() / expr_name(). However they don't support literal objects:

expr_name(x)
#> Error: `expr` must quote a symbol, scalar, or call

I think objects should be deparsed using the pillar sum type. Would that make sense? Then the error message above would become:

Column `<S3: quosures>` must be length 32 (the number of rows) or one, not 2

which makes more sense.

@lionel-
Copy link
Member Author

lionel- commented Aug 17, 2018

This also looks suboptimal for the purpose of creating default column names:

complex_var <- quote(mean(height, na.rm = TRUE, trim = 0.2))
quo_name(complex_var)
#> [1] "mean(height, na.rm = TRUE, trim = 0.2)"
tibble::tibble(mean(1:10, na.rm = TRUE, trim = 0.2))
#> # A tibble: 1 x 1
#>   `mean(1:10, na.rm = TRUE, trim = 0.2)`
#>                                    <dbl>
#> 1                                    5.5

It probably makes sense to deparse the first argument and collapse the rest:

quo_name(complex_var)
#> [1] "mean(height, ...)"

Then might need to take the max number of arguments as an option, e.g. for lobstr::cst() and rlang::trace_back().

@lionel-
Copy link
Member Author

lionel- commented Oct 1, 2018

Then might need to take the max number of arguments as an option, e.g. for lobstr::cst() and rlang::trace_back().

Or use a different _line variant, cf #636.

lionel- added a commit to lionel-/rlang that referenced this issue Oct 1, 2018
lionel- added a commit to lionel-/rlang that referenced this issue Oct 1, 2018
In addition:

- Soft-deprecate the `width` argument of quos_auto_name()
- Soft-deprecate passing a width as `.named` argument

Closes r-lib#573
lionel- added a commit to lionel-/rlang that referenced this issue Oct 1, 2018
lionel- added a commit to lionel-/rlang that referenced this issue Oct 1, 2018
In addition:

- Soft-deprecate the `width` argument of quos_auto_name()
- Soft-deprecate passing a width as `.named` argument

Closes r-lib#573
lionel- added a commit to lionel-/rlang that referenced this issue Oct 2, 2018
lionel- added a commit to lionel-/rlang that referenced this issue Oct 2, 2018
In addition:

- Soft-deprecate the `width` argument of quos_auto_name()
- Soft-deprecate passing a width as `.named` argument

Closes r-lib#573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant