-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Description
Here are two examples (based on first example from documentation for case_when()):
# Bad?
tibble(int = 1:70) |>
mutate(
response = case_when(
int %% 35 == 0 ~ "fizz buzz",
int %% 5 == 0 ~ "fizz",
int %% 7 == 0 ~ "buzz",
.default = as.character(int)
)
)
# Good?
tibble(int = 1:70) |>
mutate(
response =
case_when(
int %% 35 == 0 ~ "fizz buzz",
int %% 5 == 0 ~ "fizz",
int %% 7 == 0 ~ "buzz",
.default = as.character(int)
)
)
In the first case, the name responseobscures the fact that the arguments that follow belong to case_when(). This becomes much worse as the number of arguments and levels of nesting increase, so I would far prefer
response =
case_when(
to
response = case_when(
Thoughts? Could this be added to the guide?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels