r-quantities / errors

Uncertainty Propagation for R Vectors
https://r-quantities.github.io/errors
Other
49 stars 8 forks source link

Show Ops warnings once #22

Closed Enchufa2 closed 6 years ago

Enchufa2 commented 6 years ago

It's necessary to warn the user, but

library(errors)
library(dplyr)
library(ggplot2)

iris_e <- iris %>%
  mutate_at(vars(-Species), funs(set_errors(., .*0.02)))

ggplot(iris_e, aes(Sepal.Length, Sepal.Width, color=Species)) + 
  geom_point() + theme_bw() + theme(legend.position=c(0.6, 0.8)) +
  geom_errorbar(aes(ymin=errors_min(Sepal.Width), ymax=errors_max(Sepal.Width))) +
  geom_errorbarh(aes(xmin=errors_min(Sepal.Length), xmax=errors_max(Sepal.Length)))

generates 12 warnings:

summary(warnings())
#>                                                                    Length Class  Mode
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call
#> boolean operator not allowed for 'errors' objects, dropping errors 3      -none- call

Also, this is ok for a scripting:

set_errors(1) + set_errors(2, 0.1)

but overkilling for an interactive session. Instead,

1 + set_errors(2, 0.1)
#> Warning message:
#> In Ops.errors(1, set_errors(2, 0.1)) :
#>   first operand automatically coerced to an 'errors' object with zero error

is much more comfortable and one warning should suffice.