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

Prevent the prior calculated results from being misused #168

Merged
merged 2 commits into from
Jun 5, 2021

Conversation

yutannihilation
Copy link
Owner

@yutannihilation yutannihilation commented Jun 5, 2021

Fix #143

In the following dplyr::transmute(), a column name x in y = x refers to the previously generated column x, which is actually other_col.

data <- data.frame(x = 1, y = 2, other_col = 3)

dplyr::transmute(data,
  x = other_col,
  y = x
)

To ensure the variable refers to the original column, the expressions needs to be wrapped by data.frame and let it get auto-unspliced.

library(patchwork)
devtools::load_all("~/repo/gghighlight/")
#> ℹ Loading gghighlight
#> Loading required package: ggplot2

set.seed(22)
df <- tibble::tibble(
  week = rep(1:3, each = 3),
  values = runif(9),
  x = values,
  id = rep(c("a", "b", "c"), times = 3)
)

p1 <- ggplot(df, aes(week, values, colour = id)) +
  geom_line() +
  gghighlight(id == "a")
#> Warning: Tried to calculate with group_by(), but the calculation failed.
#> Falling back to ungrouped filter operation...
#> label_key: id

p2 <- ggplot(df, aes(week, x, colour = id)) +
  geom_line() +
  gghighlight(id == "a")
#> Warning: Tried to calculate with group_by(), but the calculation failed.
#> Falling back to ungrouped filter operation...
#> label_key: id

p1 * p2

Created on 2021-06-05 by the reprex package (v2.0.0)

@yutannihilation yutannihilation merged commit 4d97469 into master Jun 5, 2021
@yutannihilation yutannihilation deleted the fix/issue-143-transmute branch June 5, 2021 13:41
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.

gghighlight() cannot handle data containing column x
1 participant