reconhub / linelist

An R package to import, clean, and store case data
https://www.repidemicsconsortium.org/linelist
Other
25 stars 5 forks source link

improve warning for top_values in a multi-way tie #93

Open zkamvar opened 5 years ago

zkamvar commented 5 years ago

The use of the phrase "first value" in the Warning message works when there's only a two way tie, but isn't technically correct when there's a three way tie. Illustrated below:

x <- sample(rep(c("a", "b", "c", "d", "e", "f"), c(3, 3, 2, 2, 2, 1)))
top_values(x, n = 3)
 [1] "other" "c"     "b"     "other" "a"     "c"     "other" "a"     "a"     "other" "other" "b"     "b"    
Warning message:
a tie among values (c, d, e) was broken by choosing the first value 

 top_values(x, n = 4)
[1] "other" "c"     "b"     "other" "a"     "c"     "d"     "a"     "a"     "d"     "other" "b"     "b"    
Warning message:
a tie among values (c, d, e) was broken by choosing the first value 

I think for the latter, the warning message should read something like:

Warning message:
a tie among values (c, d, e) was broken by choosing the first two values 

Although important to emphasise the behaviour's still correct (the code's outputting the result we're after) so absolutely no problem at all if you can't get to this before you head off on holiday! Sorry again for the late reply and hope you have a wonderful holiday :)

Originally posted by @cwhittaker1000 in https://github.com/reconhub/linelist/pull/90#issuecomment-536005546