reconhub / linelist

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

Issue 92 #94

Closed thibautjombart closed 5 years ago

thibautjombart commented 5 years ago

This should address issue https://github.com/reconhub/linelist/issues/92

New version should be installable using:

remotes::install_github("reconhub/linelist@38e6f972cfcb")

Example of working code (see the end of the example in the doc)

x <- c("a", "a", "a", "b", "b", "c")
x
#[1] "a" "a" "a" "b" "b" "c"

top_values(x, n = 1, subset = 4:6)
#[1] "other" "other" "other" "b"     "b"     "other"

top_values(x, n = 2, subset = 4:6)
#[1] "other" "other" "other" "b"     "b"     "c"    

top_values(x, n = 1, subset = -1)
#[1] "a"     "a"     "a"     "other" "other" "other"
#Warning message:
#a tie among values (a, b) was broken by choosing the first value 

top_values(x, n = 1, subset = -1, ties_method = "last")
#[1] "other" "other" "other" "b"     "b"     "other"
#Warning message:
#a tie among values (a, b) was broken by choosing the last value 

Passes the check on:

> R.version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          6.1                         
year           2019                        
month          07                          
day            05                          
svn rev        76782                       
language       R                           
version.string R version 3.6.1 (2019-07-05)
nickname       Action of the Toes          
thibautjombart commented 5 years ago

Thanks for this! Would it be possible to add a more informative warning in in the following situation. Currently, if the subset argument is a vector of FALSEs, a cryptic warning like this gets returned:

Error in names(object) <- nm : 
  'names' attribute [4] must be the same length as the vector [1]

Here's the code I used to generate that warning:

x <- c("a", "a", "a", "b", "b", "c", "d")
dates <- as.Date(c("2019-09-09", "2019-09-09", "2019-09-10", "2019-09-10", 
                              "2019-09-11", "2019-09-11", "2019-09-12"))
top_values(x, n = 1, subset = dates > as.Date("2019-09-12"))

Would it be possible to have a more informative warning in this context?

This should be fixed via 5a665048832f7baa62af2ac1247619d1a8afd7d1

> top_values(x, subset = FALSE)
Error in top_values.factor(factor(x), n = n, replacement = replacement,  : 
  `subset` does not retain any input