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

Support case_match() #1020

Merged
merged 13 commits into from
Nov 15, 2022
Merged

Support case_match() #1020

merged 13 commits into from
Nov 15, 2022

Conversation

mgirlich
Copy link
Collaborator

@mgirlich mgirlich commented Oct 6, 2022

No description provided.

@mgirlich mgirlich marked this pull request as ready for review October 18, 2022 09:24
@mgirlich mgirlich requested a review from hadley October 18, 2022 09:26
Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for working on this!


x_expr <- enexpr(.x)
if (!is_symbol(x_expr)) {
msg <- "{.arg .x} must be a variable, not a {.obj_type_friendly {.x}}."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg <- "{.arg .x} must be a variable, not a {.obj_type_friendly {.x}}."
msg <- "{.arg .x} must be a variable, not {.obj_type_friendly {.x}}."

This always trips me up too, but obj_type_friendly adds the article because sometimes its "a" and sometimes its "an"

@@ -1,3 +1,87 @@
sql_case_match <- function(.x, ..., .default = NULL, .ptype = NULL, error_call = current_call()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need error_call here?


env <- environment(f)
f_query <- f[[2]]
# must handle `c(...)` specially because `translate_sql()` doesn't do what
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it do?

}

# catch things like `f(y)`
if (!vctrs::vec_is(f_query)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe is_call() would be more evocative of the purpose?

R/translate-sql-conditional.R Show resolved Hide resolved
tests/testthat/test-translate-sql-conditional.R Outdated Show resolved Hide resolved
})
})

test_that(".x must be a symbol", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't it also be a function?

@mgirlich mgirlich merged commit d51d58b into main Nov 15, 2022
@mgirlich mgirlich deleted the case-match branch November 15, 2022 08:28
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

Successfully merging this pull request may close these issues.

2 participants