reconhub / aweek

Convert dates to arbitrary week definitions :calendar:
https://www.repidemicsconsortium.org/aweek
Other
17 stars 4 forks source link

Error in dates with NA? #12

Closed aspina7 closed 5 years ago

aspina7 commented 5 years ago

hey - @epiamsterdam trying to run cholera template on data from mozambique. Runs in to this error, which seems to be beacuse of trying to make factor levels??

> linelist_cleaned$epiweek <- aweek::date2week(linelist_cleaned$date_of_onset, 
                                             week_start = "Monday", 
                                              floor_day = TRUE, 
                                              factor = TRUE)
Error in charToDate(x) : 
  character string is not in a standard unambiguous format

It is a date and seems normal, but has NAs:

> class(linelist_cleaned$date_of_onset)  
[1] "Date"` 
`> head(linelist_cleaned$date_of_onset, 20)
 [1] "2019-04-08" "2019-04-08" "2019-04-08" "2019-04-09" "2019-04-03" "2019-04-03" "2019-04-04" "2019-04-04"
 [9] "2019-04-04" "2019-04-04" NA           NA           NA           "2019-04-09" "2019-04-09" "2019-04-08"
[17] NA           NA           NA           NA 

The NAs seem to be recognised normally though:

> table(is.na(linelist_cleaned$date_of_onset))
FALSE  TRUE 
 2903  1408 

If you run date2week, without factor = TRUE, it works, but produces funky looking NAs

> aweek::date2week(linelist_cleaned$date_of_onset, 
                                              week_start = "Monday", 
                                              floor_day = TRUE )
<aweek start: Monday>
   [1] "2019-W15"    "2019-W15"    "2019-W15"    "2019-W15"    "2019-W14"    "2019-W14"    "2019-W14"   
   [8] "2019-W14"    "2019-W14"    "2019-W14"    "  NA-WNA-NA" "  NA-WNA-NA" "  NA-WNA-NA" "2019-W15"   
  [15] "2019-W15"    "2019-W15"    "  NA-WNA-NA" "  NA-WNA-NA" "  NA-WNA-NA" "  NA-WNA-NA" "  NA-WNA-NA"

Not sure where to go from here.... session info below just incase

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bindrcpp_0.2.2     ggspatial_1.0.3    sf_0.7-2           epitools_0.5-10    aweek_0.2.0       
 [6] incidence_1.7.0    sitrep_0.1.0       summarytools_0.8.7 ggplot2_3.1.0      dplyr_0.7.8       
[11] knitr_1.20        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0         lubridate_1.7.4    lattice_0.20-35    tidyr_0.8.3        class_7.3-14      
 [6] assertthat_0.2.0   digest_0.6.18      utf8_1.1.4         R6_2.4.0           cellranger_1.1.0  
[11] plyr_1.8.4         survey_3.33-2      e1071_1.6-8        srvyr_0.3.3        pillar_1.3.1      
[16] rlang_0.3.1        lazyeval_0.2.1     curl_3.2           readxl_1.1.0       rstudioapi_0.8    
[21] data.table_1.11.2  Matrix_1.2-14      splines_3.5.0      stringr_1.4.0      foreign_0.8-70    
[26] pander_0.6.1       ISOweek_0.6-2      RCurl_1.95-4.10    munsell_0.5.0      compiler_3.5.0    
[31] pkgconfig_2.0.2    htmltools_0.3.6    tidyselect_0.2.5   tibble_2.0.1       rio_0.5.10        
[36] codetools_0.2-15   matrixStats_0.54.0 fansi_0.4.0        crayon_1.3.4       withr_2.1.2       
[41] bitops_1.0-6       grid_3.5.0         spData_0.2.8.3     lwgeom_0.1-5       gtable_0.2.0      
[46] DBI_1.0.0          magrittr_1.5       units_0.6-2        scales_1.0.0       cli_1.0.1         
[51] stringi_1.3.1      pryr_0.1.4         rapportools_1.0    cowplot_0.9.2      openxlsx_4.0.17   
[56] tools_3.5.0        forcats_0.3.0      epitrix_0.2.1      glue_1.3.0         purrr_0.3.2       
[61] survival_2.42-3    yaml_2.2.0         colorspace_1.4-0   classInt_0.2-3     bindr_0.1.1       
[66] haven_1.1.1
zkamvar commented 5 years ago

That is most certainly and without a doubt a bug! I will get to this as soon as I get back from holiday.

Sent from my iPhone

On Apr 19, 2019, at 10:16, Alex Spina notifications@github.com wrote:

hey - @epiamsterdam trying to run cholera template on data from mozambique. Runs in to this error:

linelist_cleaned$epiweek <- aweek::date2week(linelist_cleaned$date_of_onset, week_start = "Monday", floor_day = TRUE, factor = TRUE) Error in charToDate(x) : character string is not in a standard unambiguous format

It is a date and seems normal, but has NAs:

class(linelist_cleaned$date_of_onset) [1] "Date" head(linelist_cleaned$date_of_onset, 20) [1] "2019-04-08" "2019-04-08" "2019-04-08" "2019-04-09" "2019-04-03" "2019-04-03" "2019-04-04" "2019-04-04" [9] "2019-04-04" "2019-04-04" NA NA NA "2019-04-09" "2019-04-09" "2019-04-08" [17] NA NA NA NA

The NAs seem to be recognised normally though:

table(is.na(linelist_cleaned$date_of_onset)) FALSE TRUE 2903 1408

If you run date2week, without factor = TRUE, it works, but produces funky looking NAs

aweek::date2week(linelist_cleaned$date_of_onset, week_start = "Monday", floor_day = TRUE ) [1] "2019-W15" "2019-W15" "2019-W15" "2019-W15" "2019-W14" "2019-W14" "2019-W14" [8] "2019-W14" "2019-W14" "2019-W14" " NA-WNA-NA" " NA-WNA-NA" " NA-WNA-NA" "2019-W15" [15] "2019-W15" "2019-W15" " NA-WNA-NA" " NA-WNA-NA" " NA-WNA-NA" " NA-WNA-NA" " NA-WNA-NA"

Not sure where to go from here.... session info below just incase

sessionInfo() R version 3.5.0 (2018-04-23) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] bindrcpp_0.2.2 ggspatial_1.0.3 sf_0.7-2 epitools_0.5-10 aweek_0.2.0 [6] incidence_1.7.0 sitrep_0.1.0 summarytools_0.8.7 ggplot2_3.1.0 dplyr_0.7.8 [11] knitr_1.20

loaded via a namespace (and not attached): [1] Rcpp_1.0.0 lubridate_1.7.4 lattice_0.20-35 tidyr_0.8.3 class_7.3-14 [6] assertthat_0.2.0 digest_0.6.18 utf8_1.1.4 R6_2.4.0 cellranger_1.1.0 [11] plyr_1.8.4 survey_3.33-2 e1071_1.6-8 srvyr_0.3.3 pillar_1.3.1 [16] rlang_0.3.1 lazyeval_0.2.1 curl_3.2 readxl_1.1.0 rstudioapi_0.8 [21] data.table_1.11.2 Matrix_1.2-14 splines_3.5.0 stringr_1.4.0 foreign_0.8-70 [26] pander_0.6.1 ISOweek_0.6-2 RCurl_1.95-4.10 munsell_0.5.0 compiler_3.5.0 [31] pkgconfig_2.0.2 htmltools_0.3.6 tidyselect_0.2.5 tibble_2.0.1 rio_0.5.10 [36] codetools_0.2-15 matrixStats_0.54.0 fansi_0.4.0 crayon_1.3.4 withr_2.1.2 [41] bitops_1.0-6 grid_3.5.0 spData_0.2.8.3 lwgeom_0.1-5 gtable_0.2.0 [46] DBI_1.0.0 magrittr_1.5 units_0.6-2 scales_1.0.0 cli_1.0.1 [51] stringi_1.3.1 pryr_0.1.4 rapportools_1.0 cowplot_0.9.2 openxlsx_4.0.17 [56] tools_3.5.0 forcats_0.3.0 epitrix_0.2.1 glue_1.3.0 purrr_0.3.2 [61] survival_2.42-3 yaml_2.2.0 colorspace_1.4-0 classInt_0.2-3 bindr_0.1.1 [66] haven_1.1.1

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

zkamvar commented 5 years ago

@aspina7,

Can you test this out to see if it works for you?

remotes::install_github("reconhub/aweek#14")
aspina7 commented 5 years ago

perfect! works!

zkamvar commented 5 years ago

huzzah!

On Wed, Apr 24, 2019 at 1:31 PM Alex Spina notifications@github.com wrote:

perfect! works!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/reconhub/aweek/issues/12#issuecomment-486208033, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3YRFS2CI3ACSCGFXH2FBDPSBHLNANCNFSM4HHDAC7A .