0

I'm trying to use rowwise to produce one plot per dataframe row as follows:

library(dplyr)
library(ggplot2)

params = tribble(
  ~a,  ~b,
  4, 1,
  9, 1,
  6, 2,
)


plot_beta <- function(p, a, b){
  pl <- qplot(p, dbeta(p, a, b), geom="line")
  list(pl)
}

params %>% 
  rowwise() %>% 
  mutate(gp = plot_beta(p, a, b)) %>% 
  pull(gp)

for which R returns a cool but not awesomely helpful error message:

Error:
! Obsolete data mask.
✖ Too late to resolve `a` after the end of `dplyr::mutate()`.
ℹ Did you save an object that uses `a` lazily in a column in the `dplyr::mutate()` expression ?
Run `rlang::last_error()` to see where the error occurred.

I think I do "save an object that uses a lazily in a column in the dplyr::mutate()" but that doesn't help to get how to fix this.

Changing a and b to {{a}} or .data[["a"]] doesn't help.

dotsbyname
  • 250
  • 5
  • 14
  • Where does that `p` comes from? I get an error because your function doesn't find it. I also get an error saying that `qplot` has been deprecated in ggplot2 3.4.0, so I suspect that your problem may be due to an older version of ggplot. – Claudio Feb 01 '23 at 07:50

0 Answers0