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

Computation failed in stat_summary() #1937

Closed
ericpgreen opened this issue Nov 30, 2016 · 5 comments
Closed

Computation failed in stat_summary() #1937

ericpgreen opened this issue Nov 30, 2016 · 5 comments
Labels
layers 📈 reprex needs a minimal reproducible example

Comments

@ericpgreen
Copy link

As described here, I received the following warning when I had an object in my environment called mean.

Warning message: Computation failed in stat_summary(): 'what' must be a function or character string

library(dplyr)
library(ggplot2)
set.seed(205)
dat = data.frame(t=rep(1:2, each=10), 
                 pairs=rep(1:10,2), 
                 value=rnorm(20))

ggplot(dat %>% group_by(pairs) %>%
         mutate(slope = (value[t==2] - value[t==1])/(2-1)),
       aes(t, value, group=pairs, colour=slope > 0)) +
  geom_point() +
  geom_line() +
  stat_summary(fun.y=mean,geom="line",lwd=2,aes(group=1))

A more informative warning would be helpful if possible to implement.

@hadley
Copy link
Member

hadley commented Jan 25, 2017

Thanks for providing some code that illustrates the problem — it's a great start 😄 However, your code is currently a bit too complicated: there's quite a bit of extraneous stuff in there that doesn't seem directly related to the problem. Can you please try and simplify your example some more? The more minimal you can make the reprex, the faster I can identify the problem and fix it.

@hadley hadley added reprex needs a minimal reproducible example layers 📈 labels Jan 25, 2017
@hadley
Copy link
Member

hadley commented Feb 13, 2017

I've closed this issue due to lack of requested reprex. If you still care about this bug, please open a new issue with a reprex.

@hadley hadley closed this as completed Feb 13, 2017
@zx8754
Copy link

zx8754 commented Mar 20, 2017

Adding a note as linked post is deleted at StackOverflow, the issue was caused by:

Turns out I had an object called mean in my workspace. – Eric Green Nov 30 '16 at 4:15

@klmr
Copy link
Contributor

klmr commented Jun 6, 2018

stat_summary (and similar functions that accept functions as arguments) should probably perform disambiguation internally using match.fun to avoid this issue, or at the very least give a descriptive error message.

@lock
Copy link

lock bot commented Dec 3, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Dec 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
layers 📈 reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

4 participants