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

Enable case_when(TRUE ~ default) syntax #191

Merged
merged 3 commits into from
Feb 17, 2021

Conversation

markfairbanks
Copy link
Collaborator

Currently data.table doesn't recycle the left hand side "conditions" in fcase(). This causes case_when(x == 1 ~ 1, TRUE ~ 2) syntax to fail in the current translation. fcase() also doesn't currently allow a vector for the default arg.

This implements a simple workaround that is mentioned in that issue.

R/tidyeval.R Outdated
odd_index <- as.logical(seq_along(args) %% 2)
args[odd_index] <- lapply(
args[odd_index],
function(.x) if (isTRUE(.x)) call2("rep", TRUE, quote(.N)) else .x
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be cleaner to apply to x[[2]] above — then you wouldn't need to compute the odds index.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, makes sense. All set.

@hadley hadley merged commit 081ef70 into tidyverse:master Feb 17, 2021
@hadley
Copy link
Member

hadley commented Feb 17, 2021

Thanks!

@markfairbanks markfairbanks deleted the case_when-default branch February 22, 2021 19:38
@kmishra9 kmishra9 mentioned this pull request Sep 10, 2021
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