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

rlang::qq_show return code is not same with excution #1640

Closed
djhbs opened this issue Jul 25, 2023 · 2 comments
Closed

rlang::qq_show return code is not same with excution #1640

djhbs opened this issue Jul 25, 2023 · 2 comments

Comments

@djhbs
Copy link

djhbs commented Jul 25, 2023

Hi, thank you very much for help.

In the below example, the rlang::qq_show show the right code:

tibble::tibble(a = character(0), b = integer(), c = double())

but the execution does not return right variable names, only the right type.

For first variable, the right name should be a not a = character(0)

var <- c("a = character(0)", "b = integer()", "c = double()")
rlang::qq_show(tibble::tibble(!!!rlang::parse_exprs(var)))
#> tibble::tibble(a = character(0), b = integer(), c = double())

tibble::tibble(a = character(0), b = integer(), c = double())
#> # A tibble: 0 × 3
#> # ℹ 3 variables: a <chr>, b <int>, c <dbl>

df <- tibble::tibble(!!!rlang::parse_exprs(var))
df
#> # A tibble: 0 × 3
#> # ℹ 3 variables: a = character(0) <chr>, b = integer() <int>,
#> #   c = double() <dbl>

I am not sure I use the function wrongly, but the result is strange.

@lionel-
Copy link
Member

lionel- commented Jul 25, 2023

That's because a = character(0) is an assignment expression just like a <- character(0). And you are injecting this whole assignment as individual argument.

If you want to pass names, do it via the names of the list of expressions, e.g.

exprs <- c(a = "character(0)", b = "integer()", c = "double()")

# Or equivalently:
exprs <- list(a = quote(character(0)), b = quote(integer()), c = quote(double()))

@lionel- lionel- closed this as completed Jul 25, 2023
@djhbs
Copy link
Author

djhbs commented Jul 25, 2023

Thank you so much for your detailed explanation.

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

No branches or pull requests

2 participants